what i need to need
- i need to fetch some key values and store in another array.
api data
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 code
$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);
- i need to group some data in array .
output is should be like :
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
)
)
problem its o/p array like that
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
)
- please suggest where i have done wrong.
- i need some key and value and store in another array . .
Your error is that you use array_push the wrong way : each argument you give to array_push adds another row to the array. What you want to do is to add only one row at the time, containing the desired data.
You should do like so :