3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $price = array( ); $price = array ( "adult" => array(), "child" => array()); $price['adult'][1]['2014-05-01'] = array(); $price['adult'][1]['2014-05-01']['basic_price'] = 100.00; $price['child'][1]['2014-05-01'] = array(); $price['child'][1]['2014-05-01']['basic_price'] = 0.00; $price['child'][1]['2014-05-01']['hotel_child'] = 396; $price['child'][2]['2014-05-01'] = array(); $price['child'][2]['2014-05-01']['basic_price'] = 10.00; $price['child'][2]['2014-05-01']['hotel_child'] = 407; $occ[0]['bdate'] = '01.05.2006'; $occ[0]['hotel_child_id'] = 407; print "<pre> <h4>Childovi:</h4> <br>"; print_r($occ); print "</pre>"; #print "<pre> <h4>Price arra:</h4> <br>"; #print_r($price); #print "</pre>"; $child_id = 396; function chk($id, $arr) { foreach ($arr as $a => $v) { if ($v['hotel_child_id'] == $id) { return true; } } } foreach ($price as $pr => $val) { if ($pr == "child") { foreach ($val as $ch => $vv) { foreach ($vv as $d => $v) { if (chk($v['hotel_child'], $occ)) { print $v['hotel_child'] . "<br>"; } else { unset($price[$pr][$ch]); } } } } } print "Posle: <br><br> <pre>"; print_r($price); print "</pre>";
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<pre> <h4>Childovi:</h4> <br>Array ( [0] => Array ( [bdate] => 01.05.2006 [hotel_child_id] => 407 ) ) </pre>407<br>Posle: <br><br> <pre>Array ( [adult] => Array ( [1] => Array ( [2014-05-01] => Array ( [basic_price] => 100 ) ) ) [child] => Array ( [2] => Array ( [2014-05-01] => Array ( [basic_price] => 10 [hotel_child] => 407 ) ) ) ) </pre>