3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $entity = new stdClass(); $entity->price['und'][] = array('amount' => 0, 'currency_code' => 'CAD', 'data' => FALSE); $entity->price2['und'][] = array('amount' => 0, 'currency_code' => 'CAD', 'data' => FALSE); function compare_filter($field, $array) { foreach ($array as $language => $items) { if (empty($items)) { unset($array[$language]); } else { foreach ($items as $delta => $item) { $array[$language][$delta] = array_filter(array_intersect_key($item, $field['columns'])); ksort($array[$language][$delta]); } } } return $array; } $field['columns'] = array('amount' => array(), 'currency_code' => array(), 'data' => array()); foreach (array('price', 'price2') as $field_name) { $items1 = compare_filter($field, (array) $entity->$field_name); } var_dump($entity);
based on ocNgv
Output for 5.1.0 - 7.2.0
object(stdClass)#1 (2) { ["price"]=> array(1) { ["und"]=> array(1) { [0]=> array(3) { ["amount"]=> int(0) ["currency_code"]=> string(3) "CAD" ["data"]=> bool(false) } } } ["price2"]=> array(1) { ["und"]=> array(1) { [0]=> array(3) { ["amount"]=> int(0) ["currency_code"]=> string(3) "CAD" ["data"]=> bool(false) } } } }
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined function array_intersect_key() in /in/WDqKN on line 14
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: array_intersect_key() in /in/WDqKN on line 14
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: array_intersect_key() in /in/WDqKN on line 14
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: array_intersect_key() in /in/WDqKN on line 14