<?php $customers='[ { "id": 1, "name": "sara", "phone": 1100, "mobile": 1111 }, { "id": 2, "name": "ben", "phone": 2200, "mobile": 2222 } ]'; $data = json_decode($customers, true); function findCustomerInArr($array,$customerName){ $customerFound = false; foreach($array as $a){ if(strtolower($a['name']) == strtolower($customerName)){ $customerFound = true; echo $customerName."'s phone is ".$a['phone'].PHP_EOL; echo $customerName."'s mobile is ".$a['mobile'].PHP_EOL; break; } } if(false == $customerFound){ echo "No customer found with this name".PHP_EOL; } } findCustomerInArr($data,'sara'); findCustomerInArr($data,'aliveToDie');
You have javascript disabled. You will not be able to edit any code.