How to apply a function to an array


I need to apply a function to a variable that returns this array:

"content_block_images": [
        "image": 10741
        "image": 10742

But this function only accepts that you enter the id simply that they would be these 10741. As the function accepts it would be so function (10741), some solution? PS: I need the data as they are in json because this I have to return in an API the only thing I want to do is that instead of the id the url of the image is shown for which you have to use this function wp_get_attachment_url ().

And what I'm trying to convert to url is a multidimensional array

asked by Santiago D'Antuoni 23.11.2016 в 19:42

1 answer


I do not know much about PHP, but what you should do (in any programming language) is:

  • convert the JSON to an array
  • iterate over the array
  • apply the function to each of the elements.
  • I guess PHP will look something like this:

    $data = json_decode($json);
    $array = $data->content_block_images;
    foreach ($array as $clave => $valor) {
    answered by 23.11.2016 в 19:59