In mooodle I create a course via web service the output of array that I print via command print_r is:
[{"id":29,"shortname":"math1"}]
I wanna to extract just 29 of this text via PHP how can id do it?
to do this you have to decode
the array:
<?php
$json_array = ' [{"id":29,"shortname":"math1"}]';
$php_array = json_decode($json_array);
echo $php_array[0]->id;
And you can do a foreach
loop if there is more data
Sandbox link