EDIT: Parsed the array completely (it contained unparsed JSON!)
array(22) {
[0]=>
array(4) {
["responseData"]=>
array(1) {
["translatedText"]=>
string(163) "21558299 this is the text that i want to end up with, excluding the id number at the start of the string"
}
["responseDetails"]=>
string(0) ""
["responseStatus"]=>
int(200)
The string I want to search for is the 2155.. and IFF it’s present, I want to get the string that’s after it… How can I do this? Any help much appreciated! (Or a better solution…?)
What I need is a return boolean telling me if the ID is actually contained within array – if it is, I need the text. If it’s not, I need to know as I want to put some other text (not relevant here).
Disclaimer: Gonna give this one to nickb, he’s been beyond awesome.
EDIT: This part is irrelevant now:
This is what I got so far, but it’s returning null. $trans_json is the array quoted above. $search[id] is another array, that holds the id string.
$return = array_filter( $trans_json, function($el) {
if( !( $start = strpos( $el, $search[id]) === false)) {
$str = substr( $el, $start);
return substr( $str, 0, strpos( $str, '}'));
}
return null;
});
Use
array_walk():Your example isn’t working because
$searchis undefined. You need a closure (note theuse ($search):