3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category = array( 'Account' => array( 'Show Balance' => array( 'Recharge' => 2300, 'Success' => 12000, 'Failure' => 25000, ), 'Balance History' => 'your balance is very low for last 2 years', 'Mini Statement' => 'This is your mini statement. You can have a look of your transaction details', 'Last Transaction' => 25000 ), 'Deposit' => array( 'Deposit Limit' => 40000, 'Make Deposit' => 'Please go to the nearest branch ans deposit the money.', 'Last Deposit' => 12000 ), 'FAQ' => array( 'How To Open An Account' => 'Go to your nearest branch fill up a form, submit it to the branch manger with required supporting documents.', 'How To Widraw Money' => 'Go to any atm center swipe the card enter pin and get your money.', 'How To Add Money' => 'You need to go to your nearest branch and deposit money over there.' ), 'Loan' => array( 'Home Loan' => 'This is home loan related answer', 'Personal Loan' => 'This is personal loan related answer', 'Car Loan' => 'This is car loan related answer', 'Bike Loan' => 'This is bike loan related answer' ) , 'Test', ); function getData($categoryArray, $key){ foreach($categoryArray as $k => $value){ if($k==$key) return $value; if(is_array($value)){ $find = getData($value, $key); if($find){ return $find; } } } return null; } $result1 = getData($category, 'Show Balance'); var_dump($result1); $result = getData($category, 'Recharge'); var_dump($result);
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14
array(3) { ["Recharge"]=> int(2300) ["Success"]=> int(12000) ["Failure"]=> int(25000) } int(2300)

preferences:
158.17 ms | 408 KiB | 5 Q