<?php $customer s= '[ { "id": 1, "name": "sara", "phone": 1100, "mobile": 1111 }, { "id": 2, "name": "ben", "phone": 2200, "mobile": 2222 } ]'; $seachFor = 'sara'; $foundCustomer = false; foreach(json_decode($customers, true) as $customer) { if ($customer['name'] == $seachFor) { $foundCustomer = $customer; break; } } if ($foundCustomer) { $phone = $foundCustomer['phone']; $mobile = $foundCustomer['mobile']; echo "sara's phone is $phone\n"; echo "sara's mobile is $mobile"; } else { echo "No customer found with this name"; }
You have javascript disabled. You will not be able to edit any code.