

\array_splice() needs the offset, not the key, as the second parameter.Īrray_splice(), same as unset(), take the array by reference. If you use \array_splice() the keys will automatically be reindexed, but the associative keys won’t change - as opposed to \array_values(), which will convert all keys to numerical keys. If you want to reindex the keys you can use \array_values() after unset(), which will convert all keys to numerically enumerated keys starting from 0.Ĭode: $array = Note that when you use unset() the array keys won’t change.

This only works if the element does not occur more than once, since \array_search returns the first hit only.

If you know the value and don’t know the key to delete the element you can use \array_search() to get the key. If you want to delete just one array element you can use unset() or alternatively \array_splice(). There are different ways to delete an array element, where some are more useful for some specific tasks than others. Yet i can return an indexed value echo 'First Name: '. I have json decode set to true for array output $result = json_decode($response, true) // true turns it into an arrayīut when i try to echo the 'first_name' values it just returns empty. '' // why doesnt this workĮcho 'Last Name: '. $result = json_decode($response, true) // true turns it into an arrayĮcho 'First Name: '. $response = (string)curl_exec($request) // execute curl fetch and store results in $responseĬurl_close($request) // close curl object "Content-Type: application/x-www-form-urlencoded" curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE) // uncomment if you get no gateway response and are using HTTPSĬurl_setopt($request, CURLOPT_FOLLOWLOCATION, true) Ĭurl_setopt($request, CURLOPT_HTTPHEADER, array( $request = curl_init($api) // initiate curl objectĬurl_setopt($request, CURLOPT_HEADER, 0) // set to 0 to eliminate header info from responseĬurl_setopt($request, CURLOPT_RETURNTRANSFER, 1) // Returns response data instead of TRUE(1) Trying to echo a couple of values from the CURL JSON response so i can put them in to a foreach loop but i can only get single indexed values to work.
