<?php $customers='[ { "id": 1, "name": "sara", "phone": 1100, "mobile": 1111 }, { "id": 2, "name": "ben", "phone": 2200, "mobile": 2222 } ]'; foreach(json_decode($customers, true) as $a){ if($a['name'] == 'sara'){ $phone = $a['phone']; $mobile = $a['mobile']; echo "sara's phone is $phone"; 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.