2015-06-05 2 views
0

то, что мне нужно нужнокак хранить данные из одного массива в другой в PHP

  • мне нужно принести некоторые ключевые ценности и хранить в другом массиве.

API данных

Array 
      (
      [0] => Array 
      (
      [id] => 180462 
      [des] => India International Bearing Expo New Delhi is a 3 day event being held from 5th June to the 7th June 2015 at the Delhi Haat in New Delhi, India. This 
      [membership] => 0 
      [name] => India International Bearing Expo New Delhi 
      [abbr_name] => India International Bearing Expo 
      [paid] => 0 
      [event_wrapper] => 
      [event_samll_wrapper] => http://im.gifbt.com/industry/14-350x210.jpg 
      [event_url] => india-international-bearing-expo-newdelhi 
      [website] => http://www.bearingexpo.com/ 
      [eventType] => 1 
      [venue_name] => Delhi Haat 
      [startDate] => 2015-06-05 
      [endDate] => 2015-06-07 
      [city] => New Delhi 
      [country] => India 
      [country_url] => india 
      [country_shortname] => India 
      [industry_id] => 14 
      [industry_name] => Industrial Products 
      [industry_url] => industrial-products 
      [event_status] => 
      [total_visitors] => 19 
      [total_exhibitor] => 0 
      [total_speakers] => 0 
      ) 

      [1] => Array 
      (
      [id] => 185988 
      [des] => The International Conference On Advances in Electrical, Power Control, Electronics and Communication Engineering, organized by the Krishi Sanskriti wi 
      [membership] => 
      [name] => International Conference On Advances in Electrical, Power Control, Electronics and Communication Engineering 
      [abbr_name] => AEPCECE 
      [paid] => 
      [event_wrapper] => 
      [event_samll_wrapper] => http://im.gifbt.com/industry/55-350x210.jpg 
      [event_url] => aepcece 
      [website] => http://krishisanskriti.org/aepcece.html 
      [eventType] => 2 
      [venue_name] => Jawaharlal Nehru University 
      [startDate] => 2015-06-06 
      [endDate] => 2015-06-07 
      [city] => New Delhi 
      [country] => India 
      [country_url] => india 
      [country_shortname] => India 
      [industry_id] => 55 
      [industry_name] => Business Services 
      [industry_url] => business-consultancy 
      [event_status] => 
      [total_visitors] => 11 
      [total_exhibitor] => 0 
      [total_speakers] => 0 
      ) 

      [2] => Array 
      (
      [id] => 193245 
      [des] => The International Conference on Advances in Healthcare Management Services, organized by the Indian Institute of Management will take place from 6th J 
      [membership] => 
      [name] => International Conference on Advances in Healthcare Management Services 
      [abbr_name] => International Conference on Advances in Healthcare 
      [paid] => 
      [event_wrapper] => 
      [event_samll_wrapper] => http://im.gifbt.com/industry/55-350x210.jpg 
      [event_url] => international-conference-on-advances-in-healthcare 
      [website] => http://www.iimahd.ernet.in/cmhsconf2015/ 
      [eventType] => 2 
      [venue_name] => Indian Institute of Management 
      [startDate] => 2015-06-06 
      [endDate] => 2015-06-07 
      [city] => Ahmedabad 
      [country] => India 
      [country_url] => india 
      [country_shortname] => India 
      [industry_id] => 55 
      [industry_name] => Business Services 
      [industry_url] => business-consultancy 
      [event_status] => 
      [total_visitors] => 7 
      [total_exhibitor] => 0 
      [total_speakers] => 0 
      ) 

      ) 

PHP код

  $noty = array(); 
      $notification=json_decode($notifications,true); 
      //print_r($notifications); 
      foreach($notification as $key =>$value) 
      { 

       $id['id']=$value['id']; 
       $name['name']=$value['name']; 
       $abbr_name['abbr_name']=$value['abbr_name']; 
       $startDate['startDate']=$value['startDate']; 
       $endDate['endDate']=$value['endDate']; 
        $city['city']=$value['city']; 
        $country['country']=$value['country']; 
        $data[$key]=array_push($noty,$id,$name,$abbr_name, $startDate,$endDate,$city,$country); 

      } 

     $n=json_encode($noty,true); 
  • мне нужно сгруппировать некоторые данные в массиве.

выход должен быть как:

    Array 
      (
      [0] => Array 
      (
      [id] => 180462 

      [venue_name] => Delhi Haat 
      [startDate] => 2015-06-05 
      [endDate] => 2015-06-07 
      [city] => New Delhi 
      [country] => India 
      [country_url] => india 
      [country_shortname] => India 


      ) 

      [1] => Array 
      (
      [id] => 185988 

      [membership] => 
      [name] => International Conference On Advances in Electrical, Power Control, Electronics and Communication Engineering 
      [abbr_name] => AEPCECE 
      [paid] => 
      [event_wrapper] => 
      [event_samll_wrapper] => http://im.gifbt.com/industry/55-350x210.jpg 
      [event_url] => aepcece 

      [venue_name] => Jawaharlal Nehru University 
      [startDate] => 2015-06-06 
      [endDate] => 2015-06-07 
      [city] => New Delhi 
      [country] => India 

      ) 

      [2] => Array 
      (
      [id] => 193245 

      [name] => International Conference on Advances in Healthcare Management Services 
      [abbr_name] => International Conference on Advances in Healthcare 

      [event_samll_wrapper] => http://im.gifbt.com/industry/55-350x210.jpg 
      [event_url] => international-conference-on-advances-in-healthcare 
      [website] => http://www.iimahd.ernet.in/cmhsconf2015/ 
      [eventType] => 2 
      [venue_name] => Indian Institute of Management 
      [startDate] => 2015-06-06 
      [endDate] => 2015-06-07 
      [city] => Ahmedabad 
      [country] => India 

      ) 

      ) 

проблемы его о/р массив как то

Array 
(
[0] => Array 
    (
     [id] => 180462 
    ) 

[1] => Array 
    (
     [name] => India International Bearing Expo New Delhi 
    ) 

[2] => Array 
    (
     [abbr_name] => India International Bearing Expo 
    ) 

[3] => Array 
    (
     [startDate] => 2015-06-05 
    ) 

[4] => Array 
    (
     [endDate] => 2015-06-07 
    ) 

[5] => Array 
    (
     [city] => New Delhi 
    ) 
  • пожалуйста предположить, где я сделал неправильно.
  • Мне нужен какой-то ключ и значение и хранить в другом массиве. .

ответ

1

Ваша ошибка в том, что вы используете array_push не так: каждый аргумент, который вы передаете array_push, добавляет еще одну строку в массив. Что вы хотите сделать, это добавить только одну строку в то время, содержащую требуемые данные.

Вы должны сделать так:

<?php 

$noty = array(); 
$notification=json_decode($notifications,true); 
//print_r($notifications); 
foreach($notification as $key =>$value) 
{ 
    array_push($noty, array(
     'id' => $value['id'], 
     'name' => $value['name'], 
     'abbr_name' => $value['abbr_name'], 
     'startDate' => $value['startDate'], 
     'endDate' => $value['endDate'], 
     'city' => $value['city'], 
     'id' => $value['id'], 
     'country' => $value['country'], 
     )); 
} 
$n=json_encode($noty,true); 
+0

благодарственного фр помощью – afeef

+0

Вы долгожданный :) Не забудьте пометить вопрос, как ответ, если ваша проблема решена. –

+0

Это была глупая ошибка, которую я сделал – afeef

Смежные вопросы