Having the following string:
"[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]"
How can I get the 1
from the required
part? I need just the 1
.
Thanks in advance.
Having the following string:
"[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]"
How can I get the 1
from the required
part? I need just the 1
.
Thanks in advance.
Assuming the string will always be JSON, use json_decode()
:
$array = json_decode('[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]');
Now you can access the required
option as follows:
$array[0]->required;
You can use json_decode:
<?php
$string = '[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]';
$string_array = json_decode($string, true);
echo $string_array[0]['required'];
?>
In single line, using the functions json_decode and current:
$str = '[{"name":null,"value":"","target":null,"alias":"","required":1,"showNull":0}]';
$required = current(json_decode($str))->required;