PHP nested array remove specific keys by condition - php

I am using PHP 5.5.2 with MySQL back-end. I have a self-referencing database table from that I am getting an array as below :
Array
(
[0] => Array
(
[id] => 47
[s_id] =>
[m_id] =>
[title] => Aaa
[type] => G
[created_at] => 2014-08-29 06:05:18
[frequency] => d
[start] => 2014-08-29
[time] => 09:00
[children] => Array
(
[0] => Array
(
[id] => 48
[s_id] => 37
[m_id] =>
[title] => bbbbbbbbbbbbb
[type] => Q
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
[0] => Array
(
[id] => 49
[s_id] => 38
[m_id] =>
[title] => cccccccccc
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[1] => Array
(
[id] => 50
[s_id] => 39
[m_id] =>
[title] => ddddddddd dddd
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[2] => Array
(
[id] => 51
[s_id] => 40
[m_id] =>
[title] => eeeeeee eeeeeee.
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[children] => Array
(
)
)
)
)
[1] => Array
(
[id] => 54
[s_id] => 18
[m_id] =>
[title] => fffffffff ffff
[type] => Q
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
[0] => Array
(
[id] => 55
[s_id] => 19
[m_id] =>
[title] => gggggg gggggg
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[1] => Array
(
[id] => 56
[s_id] => 20
[m_id] =>
[title] => hhhhhhhhhh hhhh
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[children] => Array
(
)
)
)
)
[2] => Array
(
[id] => 57
[s_id] => 21
[m_id] =>
[title] => iiiiiiii iiii
[type] => Q
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[children] => Array
(
[0] => Array
(
[id] => 58
[s_id] => 22
[m_id] =>
[title] => jjjjjjj jjj
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[1] => Array
(
[id] => 59
[s_id] => 23
[m_id] =>
[title] => kkkkkkkk kkkk
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
)
)
)
)
[1] => Array
(
[id] => 47
[s_id] =>
[m_id] =>
[title] => xxxx xxx xxx
[type] => G
[created_at] => 2014-08-29 06:05:18
[frequency] => d
[start] => 2014-08-29
[time] => 09:00
[children] => Array
(
[0] => Array
(
[id] => 112
[s_id] => 37
[m_id] =>
[title] => lllllllllll llllll
[type] => Q
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
[0] => Array
(
[id] => 113
[s_id] => 38
[m_id] =>
[title] => mmmmmmm mmmm
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[1] => Array
(
[id] => 123
[s_id] => 39
[m_id] =>
[title] => nnnnnnnnn hhhhh
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
)
)
[1] => Array
(
[id] => 456
[s_id] => 18
[m_id] =>
[title] => ppppppp pppppp
[type] => Q
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
[0] => Array
(
[id] => 545
[s_id] => 19
[m_id] =>
[title] => qqqqqqqqq qqq
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[time] =>
[children] => Array
(
)
)
[1] => Array
(
[id] => 435
[s_id] => 20
[m_id] =>
[title] => ssssssssss sssssssssss
[type] => A
[created_at] => 2014-08-29 06:05:18
[frequency] =>
[start] =>
[children] => Array
(
)
)
)
)
)
)
)
There might be N nesting levels in this array.
Now for each array element, if ['type'] is G then I want to remove keys [s_id] and [m_id] and for any other type I want to remove keys [start], [end] and [time].
Edit : I have tried using a recursive function but it is not giving the desired result.
private function getarray(array &$arr){
foreach ($arr as $item)
{
switch ($item['type'])
{
case 'G' :
unset($item['s_id'], $item['m_id']);
break;
default :
unset($item['start'], $item['end'], $item['time']);
break;
}
foreach ($item["children"] as $c)
{
$child = array();
getarray($child);
}
}
}
How can I achieve this?
Thanks.

function filterMyArray($arr){
if(isset($arr['type'] && $arr['type'] == 'G'){
unset($arr['s_id']);
unset($arr['m_id']);
}
else if(isset($arr['type']){
unset($arr['start']);
unset($arr['end']);
unset($arr['time']);
}
if(isset($arr['children'])
$arr['children'] = filterMyArray($arr['children']);
return $arr;
}
This function is not tested, I wrote it from memory.
But seriously, Googling something like that doesn't hurt. It would take you 5 minutes to get all the required knowledge to do this...

Resolved it myself :
private function getarray(array &$arr){
foreach ($arr as &$item)
{
switch ($item['type'])
{
case 'G' :
unset($item['s_id'], $item['m_id']);
break;
default :
unset($item['start'], $item['end'], $item['time']);
break;
}
if (is_array($item['children']) && sizeof($item['children']) > 0){
getarray($item['children']);
}
}
}
And this is working fine. I have posted this answer to help other people who are novice to php and trying to overcome their problem.
And this is a slap to the jealous people who did not helped me but asked "What did you tried so long?" with a superiority complex attitude. I did it myself.

Related

Laravel Foreach with a multidimensional array

I'm using Laravel and I wonder how can I put this array in a foreach? for read it
stdClass Object ( [data] => Array ( [0] => stdClass Object ( [id] => 0001 [type] => Item [attributes] => stdClass Object ( [product_name] => ST Slotted Sport Brake Rotors [part_number] => st126.39027SL [mfr_part_number] => 126.39027SL [part_description] => StopTech Power Slot 00-04 Volvo S40/V40 Front Left Slotted Rotor [category] => Brakes, Rotors & Pads [subcategory] => Brake Rotors - Slotted [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 15 [width] => 15 [height] => 4 [weight] => 12 ) ) [brand_id] => 56 [brand] => Stoptech [price_group_id] => 129 [price_group] => Stoptech [active] => 1 [regular_stock] => [dropship_controller_id] => 19 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/fa33cfb5-0c91-47de-9a49-67f4175a5bff-100.jpg [barcode] => 805890204282 ) ) [1] => stdClass Object ( [id] => 078595 [type] => Item [attributes] => stdClass Object ( [product_name] => RAD Clutch Fork Stop [part_number] => rad20-0262 [mfr_part_number] => 20-0262 [part_description] => Radium Engineering Mitsubishi Evo 8-10 Clutch Fork Stop [category] => Drivetrain [subcategory] => Clutch Uncategorized [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 4.5 [height] => 4.5 [weight] => 0.5 ) ) [brand_id] => 148 [brand] => Radium Engineering [price_group_id] => 406 [price_group] => Radium Engineering [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 81 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d32vzsop7y1h3k.cloudfront.net/adb8244ed2d562e078c5ce2928750f2a.JPG ) ) [2] => stdClass Object ( [id] => 095906 [type] => Item [attributes] => stdClass Object ( [product_name] => MLR Trans Rebuild Kits [part_number] => mlr88075K [mfr_part_number] => 88075K [part_description] => McLeod Performance Transmission Rebuild Kit w/ Kolene Steels 4L80E 1997-2011 - Stage 1 [category] => Drivetrain [subcategory] => Transmission Rebuild Kits [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 24 [width] => 16 [height] => 5.25 [weight] => 14.75 ) ) [brand_id] => 169 [brand] => McLeod Racing [price_group_id] => 456 [price_group] => McLeod Racing [active] => 1 [regular_stock] => [dropship_controller_id] => 116 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) ) ) [3] => stdClass Object ( [id] => 1 [type] => Item [attributes] => stdClass Object ( [product_name] => TXS Boost Controllers [part_number] => txs-BC-HPBC [mfr_part_number] => txs-BC-HPBC [part_description] => Turbo XS High Performance Boost Controller [category] => Forced Induction [subcategory] => Boost Controllers [dimensions] => Array ( [0] => stdClass Object ( [box_number] => 1 [length] => 4.75 [width] => 3.25 [height] => 2.25 [weight] => 0.5 ) ) [brand_id] => 63 [brand] => Turbo XS [price_group_id] => 130 [price_group] => Turbo XS [active] => 1 [regular_stock] => 1 [dropship_controller_id] => 0 [air_freight_prohibited] => [not_carb_approved] => [prop_65] => Unknown [warehouse_availability] => Array ( [0] => stdClass Object ( [location_id] => 01 [can_place_order] => 1 ) [1] => stdClass Object ( [location_id] => 02 [can_place_order] => 1 ) [2] => stdClass Object ( [location_id] => 59 [can_place_order] => 1 ) ) [thumbnail] => https://d5otzd52uv6zz.cloudfront.net/92670bde-a650-4ae6-a53e-0da8b2a26d1c-100.jpg [barcode] => 053176487038 ) )
Thanks!
Just loop through your data with
foreach($yourvar->data as $key=> $data){
echo $data->id;
}
If you get an StdClass object it means you're iterating over an object through -> if you've an array you can print through $data['key']

How to compare Associative Array in CodeIgniter

Array
(
[records] => Array
(
[0] => stdClass Object
(
[id] => 6
[fname] => hardik
[type] => Active
[rid] => 1
[rname] => Principle
[uid] => 48
)
[1] => stdClass Object
(
[id] => 12
[fname] => gautam
[type] => De-Active
[rid] => 1
[rname] => Principle
[uid] => 54
)
[2] => stdClass Object
(
[id] => 10
[fname] => burhan
[type] => Active
[rid] => 2
[rname] => Teacher
[uid] => 52
)
[3] => stdClass Object
(
[id] => 13
[fname] => gautam
[type] => De-Active
[rid] => 2
[rname] => Teacher
[uid] => 54
)
[4] => stdClass Object
(
[id] => 7
[fname] => abc
[password] => d41d8cd98f00b204e9800998ecf8427e
[type] => Active
[rid] => 3
[rname] => Parent
[uid] => 49
)
)
)
How can I compare associative array in Codeigniter for remove duplicate user?

cakePHP multidimensional array loop back to previous push

I have created an array which I need to show a list of projects for the current user. Each project is made up of stages, each stage can have multiple KPIs assigned to it.
As you can see the stages are appended to the array fine and for the most part so are the KPIs.
The exception to this is with KPIs that are not stage specific. When I have this type of KPI is should be assigned to the project section, as it spans multiple stages.
KPIs are assigned to stages by the PSID, if the id is null then it is a project wide KPI.
The issue I'm having is with the project wide KPIs. They are repeated, I need each KPI to appear once in the array.
I've tried to check the previously pushed array element with the currently pushed one in order to check.
$i=0;
foreach($projects as $project){
$projectStages = $this->ProjectStages->find('all',
array(
'conditions' => array(
'pid' => $project['Projects']['pid']
)
)
);
array_push($projects[$i], $projectStages);
$n=0;
foreach($projectStages as $stage){
$projectKPIs = $this->ProjectKPIs->find('all',
array(
'conditions' => array(
'nPid' => $project['Projects']['pid']
)
)
);
foreach($projectKPIs as $projectKPI){
if(empty($projectKPI['ProjectKPIs']['nPsid'])){
$N = $n-1;
$curpkid = $projectKPI['ProjectKPIs']['pkid'];
if(isset($projects[$i]['Projects'][$N]['ProjectKPIs']['pkid'])){
$prevpkid = $projects[$i]['Projects'][$N]['ProjectKPIs']['pkid'];
}else{
$prevpkid = null;
}
if($curpkid != $prevpkid){
echo 'cur: '.$curpkid.' - prev: '.$prevpkid;
array_push($projects[$i]['Projects'], $projectKPI);
}
}else if($projectKPI['ProjectKPIs']['nPsid'] == $stage['ProjectStages']['psid']){
array_push($projects[$i][$i][$n]['ProjectStages'], $projectKPI);
}
}
$n++;
}
$i++;
}
Below is the code I'm using and the array I'm currently getting back:
Array
(
[0] => Array
(
[Projects] => Array
(
[pid] => 811
[name] => Kpi Project
[description] => This Project Has Kpis
[scheduledStartDate] => 2015-05-01
[scheduledEndDate] => 2015-06-01
[actualStartDate] =>
[actualEndDate] =>
[pmid] => 1137
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 37
[nPsid] =>
[type] => 1
[start] => 2015-05-03
[end] => 2015-05-09
[nPid] => 811
[nKid] => 7
)
)
[1] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 37
[nPsid] =>
[type] => 1
[start] => 2015-05-03
[end] => 2015-05-09
[nPid] => 811
[nKid] => 7
)
)
[2] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 37
[nPsid] =>
[type] => 1
[start] => 2015-05-03
[end] => 2015-05-09
[nPid] => 811
[nKid] => 7
)
)
[3] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 37
[nPsid] =>
[type] => 1
[start] => 2015-05-03
[end] => 2015-05-09
[nPid] => 811
[nKid] => 7
)
)
[4] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 37
[nPsid] =>
[type] => 1
[start] => 2015-05-03
[end] => 2015-05-09
[nPid] => 811
[nKid] => 7
)
)
)
[pm] => Array
(
[first_name] => Mr
[last_name] => A
)
[0] => Array
(
[0] => Array
(
[ProjectStages] => Array
(
[psid] => 99
[pid] => 811
[stageID] => 1
[name] => 1
[description] => 1
[label] => 1
[actualStartDate] => 0000-00-00
[scheduledStartDate] => 2015-05-01
[actualEndDate] => 0000-00-00
[scheduledEndDate] => 2015-05-08
[prevStage] => n
[keyStage] => n
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 32
[nPsid] => 99
[type] => 0
[start] =>
[end] =>
[nPid] => 811
[nKid] => 2
)
)
)
)
[1] => Array
(
[ProjectStages] => Array
(
[psid] => 100
[pid] => 811
[stageID] => 2
[name] => 2
[description] => 2
[label] => 2
[actualStartDate] => 0000-00-00
[scheduledStartDate] => 2015-05-08
[actualEndDate] => 0000-00-00
[scheduledEndDate] => 2015-05-15
[prevStage] => n
[keyStage] => n
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 33
[nPsid] => 100
[type] => 0
[start] =>
[end] =>
[nPid] => 811
[nKid] => 4
)
)
)
)
[2] => Array
(
[ProjectStages] => Array
(
[psid] => 101
[pid] => 811
[stageID] => 3
[name] => 3
[description] => 3
[label] => 3
[actualStartDate] => 0000-00-00
[scheduledStartDate] => 2015-05-15
[actualEndDate] => 0000-00-00
[scheduledEndDate] => 2015-05-22
[prevStage] => n
[keyStage] => n
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 34
[nPsid] => 101
[type] => 0
[start] =>
[end] =>
[nPid] => 811
[nKid] => 5
)
)
)
)
[3] => Array
(
[ProjectStages] => Array
(
[psid] => 102
[pid] => 811
[stageID] => 4
[name] => 4
[description] => 4
[label] => 4
[actualStartDate] => 0000-00-00
[scheduledStartDate] => 2015-05-22
[actualEndDate] => 0000-00-00
[scheduledEndDate] => 2015-05-29
[prevStage] => n
[keyStage] => n
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 35
[nPsid] => 102
[type] => 0
[start] =>
[end] =>
[nPid] => 811
[nKid] => 6
)
)
)
)
[4] => Array
(
[ProjectStages] => Array
(
[psid] => 103
[pid] => 811
[stageID] => 5
[name] => 5
[description] => 5
[label] => 5
[actualStartDate] => 0000-00-00
[scheduledStartDate] => 2015-05-29
[actualEndDate] => 0000-00-00
[scheduledEndDate] => 2015-06-01
[prevStage] => n
[keyStage] => n
[0] => Array
(
[ProjectKPIs] => Array
(
[pkid] => 36
[nPsid] => 103
[type] => 0
[start] =>
[end] =>
[nPid] => 811
[nKid] => 8
)
)
)
)
)
)
[1] => Array
(
[Projects] => Array
(
[pid] => 572
[name] => Sgh
[description] => Dfgh
[scheduledStartDate] => 2015-04-01
[scheduledEndDate] => 2015-05-01
[actualStartDate] =>
[actualEndDate] =>
[pmid] => 3304
)
[pm] => Array
(
[first_name] => Mr
[last_name] => Brown
)
[0] => Array
(
)
)
)
It seems that you are retrieving the same exact database results multiple times. I'm looking at the find in this code block:
foreach($projectStages as $stage){
$projectKPIs = $this->ProjectKPIs->find('all',
array(
'conditions' => array(
'nPid' => $project['Projects']['pid']
)
)
);
// ...
}
It looks to me that you are going to get the same result set for $projectKPIs on each iteration of the foreach $projectStages because the find for ProjectKPIs is using the project id and nothing to do with whatever the current $stage is.
So effectively for every stage you then loop over all the same KPIs again, causing your logic to get convoluted trying to avoid duplicates.
Perhaps this can be simplified by restructuring your foreach loops. I would ditch the outer foreach($projectStages as $stage) and then iterate over all the KPIs only once. Then inside that loop iterate over each stage only when you need to test against the $stage['ProjectStages']['psid'], which may actually be unnecessary at that point.

Zend paginator not working properly when array format is not as it should be

Hi my zend paginator works well when the $business_list array format is like below.
but when the array format changes it displays only one page instead of many pages.
$paginator = Zend_Paginator::factory($business_list);
Array
(
[0] => Array
(
[id] => 216
[userid] => 141
[title] => first req
[image] =>
[logo] =>
[description] =>
this is the first requirment
[date] => 2012-06-12 10:31:01
[area] => 1
[budget] => 1
[type] => 1
[status] => 1
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 315
[business_id] => 216
[section_id] => 1
[subsection_id] => 13
[description] =>
)
[1] => Array
(
[id] => 316
[business_id] => 216
[section_id] => 3
[subsection_id] => 14
[description] =>
)
[2] => Array
(
[id] => 317
[business_id] => 216
[section_id] => 4
[subsection_id] => 15
[description] =>
)
)
[CmUser] => Array
(
[id] => 141
[username] => venki
[password] =>
[firstname] => venkatesh
[lastname] => abus
[image] => 54winter.jpg
[email] => xxx#xx.com
[phone] => 23423452
[group_id] => 2
[status] =>
[registered_date] => 2012-06-04 06:32:58
[last_visit] => 0000-00-00 00:00:00
[is_active] => 1
[subscribe] => 1
)
)
[1] => Array
(
[id] => 214
[userid] => 98
[title] => gopicontractor
[image] => 54bluehills.jpg
[logo] => 239waterlilies.jpg
[description] =>
TIt uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is
[date] => 2012-06-11 12:18:58
[area] => 1
[budget] => 1
[type] => 3
[status] => 1
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 305
[business_id] => 214
[section_id] => 1
[subsection_id] => 5
[description] =>
)
[1] => Array
(
[id] => 306
[business_id] => 214
[section_id] => 1
[subsection_id] => 6
[description] =>
)
[2] => Array
(
[id] => 307
[business_id] => 214
[section_id] => 3
[subsection_id] => 1
[description] =>
)
[3] => Array
(
[id] => 308
[business_id] => 214
[section_id] => 4
[subsection_id] => 9
[description] =>
)
)
[CmUser] => Array
(
[id] => 98
[username] => gopi.s
[password] =>
[firstname] => venkatesh
[lastname] => franc
[image] =>
[email] => ss#ss.com
[phone] => 23423452
[group_id] => 3
[status] =>
[registered_date] => 2012-05-16 12:36:57
[last_visit] => 0000-00-00 00:00:00
[is_active] => 1
[subscribe] => 1
)
)
)
the above array format displays paginatin correctly.
This is the array that displays only one page in pagination.
Zend_Paginator Object
(
[_cacheEnabled:protected] => 1
[_adapter:protected] => Zend_Paginator_Adapter_Array Object
(
[_array:protected] => Array
(
[0] => Array
(
[id] => 89
[username] => xx
[password] => xx
[firstname] => xx
[lastname] => xx
[image] =>
[email] => xx#ymail.com
[phone] => 2342345
[group_id] => 2
[status] => offline
[registered_date] => 2012-05-15 10:58:53
[last_visit] =>
[is_active] => 1
[subscribe] => 0
[CmBusiness] => Array
(
[0] => Array
(
[id] => 204
[userid] => 89
[title] => xxhousing
[image] => 760067.jpg
[logo] => xx_818f3c97e6_o.jpg
[description] => xx
[date] => 2012-05-31 13:36:17
[area] => 1
[budget] => 1
[type] => 1
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 251
[business_id] => 204
[section_id] => 1
[subsection_id] => 6
[description] => xx
)
[1] => Array
(
[id] => 252
[business_id] => 204
[section_id] => 3
[subsection_id] => 2
[description] => xx
)
[2] => Array
(
[id] => 253
[business_id] => 204
[section_id] => 3
[subsection_id] => 4
[description] => xx
)
[3] => Array
(
[id] => 254
[business_id] => 204
[section_id] => 4
[subsection_id] => 9
[description] => xx
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 1
[type] => Personal business
[status] => 1
)
)
[1] => Array
(
[id] => 205
[userid] => 89
[title] => xx
[image] => 41217850-desktop-wallpapers-new-windows-xp.jpg
[logo] => 356anger_n.jpg
[description] => xx
[date] => 2012-05-31 13:37:15
[area] => 1
[budget] => 1
[type] => 3
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 255
[business_id] => 205
[section_id] => 1
[subsection_id] => 6
[description] =>xx
)
[1] => Array
(
[id] => 256
[business_id] => 205
[section_id] => 3
[subsection_id] => 1
[description] => xx
)
[2] => Array
(
[id] => 257
[business_id] => 205
[section_id] => 3
[subsection_id] => 2
[description] => xx
)
[3] => Array
(
[id] => 258
[business_id] => 205
[section_id] => 4
[subsection_id] => 10
[description] => xx
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 3
[type] => Bilde companies
[status] => 1
)
)
[2] => Array
(
[id] => 206
[userid] => 89
[title] => Nuestros recursos
[image] =>
[logo] =>
[description] => xx
[date] => 2012-05-31 13:38:04
[area] => 1
[budget] => 1
[type] => 4
[status] => 1
[CmAmount] => Array
(
[id] => 1
[amount] => 1000-1500
[status] => 1
)
[CmBusinessSection] => Array
(
[0] => Array
(
[id] => 259
[business_id] => 206
[section_id] => 1
[subsection_id] => 5
[description] =>
)
[1] => Array
(
[id] => 260
[business_id] => 206
[section_id] => 1
[subsection_id] => 6
[description] =>
)
[2] => Array
(
[id] => 261
[business_id] => 206
[section_id] => 3
[subsection_id] => 2
[description] =>
)
[3] => Array
(
[id] => 262
[business_id] => 206
[section_id] => 4
[subsection_id] => 10
[description] =>
)
)
[CmArea] => Array
(
[id] => 1
[area] => manchester
[status] => 1
)
[CmType] => Array
(
[id] => 4
[type] => Designer
[status] => 1
)
)
)
)
)
[_count:protected] => 1
)
[_currentItemCount:protected] =>
[_currentItems:protected] =>
[_currentPageNumber:protected] => 1
[_filter:protected] =>
[_itemCountPerPage:protected] => 2
[_pageCount:protected] => 1
[_pageRange:protected] =>
[_pages:protected] =>
[_view:protected] =>
)

Removing an array result

[5] => Array
(
[id] => 29372
[product_id] => Array
(
[0] => stdClass Object
(
[id] => 1469
[type_id] => 1
[title] => Hearth 2 Hearth
[cover] => 21cf9d7d09d403251ba5d01ff33cd089.jpg
[coverid] => 1178
[inserted_by] => 0
[inserted_date] => 2011-02-11 13:55:23
[status_id] => 0
)
)
[variable_id] => 9
[variable_value] => 2011-02-11
[master_value] =>
[released_date] => 2011-02-11
[price] => Array
(
[0] => Array
(
[product_id] => 1469
[media_format] => VCD
[price] => 29000
[discount] => 5
)
)
[media_format] => VCD
)
[6] => Array
(
[id] => 30074
[product_id] => Array
(
[0] => stdClass Object
(
[id] => 1470
[type_id] => 1
[title] => Hearth 2 Hearth
[cover] => 149ddd4d1d5e567c1300d4831323e1c5.jpg
[coverid] => 1177
[inserted_by] => 6
[inserted_date] => 2011-02-16 15:18:58
[status_id] => 0
)
)
[variable_id] => 9
[variable_value] => 2011-02-11
[master_value] =>
[released_date] => 2011-02-11
[price] => Array
(
[0] => Array
(
[product_id] => 1470
[media_format] => DVD
[price] => 39000
[discount] => 0
)
)
[media_format] => DVD
)
I want the result by media_format = DVD so the whole array is gone, is there anyway to delete an array or remove it?
The same way you "delete" any variable:
unset($array[$index]);

Categories