<?php
header("Access-Control-Allow-Origin: *");
$json_string = '{
"nodes": [
{ "id": "0", "type": "food" },
{ "id": "1", "type": "drinks" },
{ "id": "2", "type": "snacks" },
{ "id": "3", "type": "food" },
{ "id": "4", "type": "drinks" }
],
"links": [
{ "source": "0", "target": "1"},
{ "source": "1", "target": "2"},
{ "source": "2", "target": "0"}
]
}';
// converts json_string to array
$json = json_decode($json_string);
printf("%s\n", json_encode($json, JSON_PRETTY_PRINT));
unset($json -> nodes[3]);
printf("%s\n", json_encode($json, JSON_PRETTY_PRINT));
$json = array_values($json);
$json = json_encode($json);
printf("%s\n", $json)
?>
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.26, 8.4.1 - 8.4.13
- {
"nodes": [
{
"id": "0",
"type": "food"
},
{
"id": "1",
"type": "drinks"
},
{
"id": "2",
"type": "snacks"
},
{
"id": "3",
"type": "food"
},
{
"id": "4",
"type": "drinks"
}
],
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
{
"nodes": {
"0": {
"id": "0",
"type": "food"
},
"1": {
"id": "1",
"type": "drinks"
},
"2": {
"id": "2",
"type": "snacks"
},
"4": {
"id": "4",
"type": "drinks"
}
},
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, stdClass given in /in/XPbuo:30
Stack trace:
#0 /in/XPbuo(30): array_values(Object(stdClass))
#1 {main}
thrown in /in/XPbuo on line 30
Process exited with code 255. - Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
{
"nodes": [
{
"id": "0",
"type": "food"
},
{
"id": "1",
"type": "drinks"
},
{
"id": "2",
"type": "snacks"
},
{
"id": "3",
"type": "food"
},
{
"id": "4",
"type": "drinks"
}
],
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
{
"nodes": {
"0": {
"id": "0",
"type": "food"
},
"1": {
"id": "1",
"type": "drinks"
},
"2": {
"id": "2",
"type": "snacks"
},
"4": {
"id": "4",
"type": "drinks"
}
},
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
Fatal error: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, stdClass given in /in/XPbuo:30
Stack trace:
#0 /in/XPbuo(30): array_values(Object(stdClass))
#1 {main}
thrown in /in/XPbuo on line 30
Process exited with code 255. - Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
- {
"nodes": [
{
"id": "0",
"type": "food"
},
{
"id": "1",
"type": "drinks"
},
{
"id": "2",
"type": "snacks"
},
{
"id": "3",
"type": "food"
},
{
"id": "4",
"type": "drinks"
}
],
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
{
"nodes": {
"0": {
"id": "0",
"type": "food"
},
"1": {
"id": "1",
"type": "drinks"
},
"2": {
"id": "2",
"type": "snacks"
},
"4": {
"id": "4",
"type": "drinks"
}
},
"links": [
{
"source": "0",
"target": "1"
},
{
"source": "1",
"target": "2"
},
{
"source": "2",
"target": "0"
}
]
}
Warning: array_values() expects parameter 1 to be array, object given in /in/XPbuo on line 30
null
preferences:
157.1 ms | 416 KiB | 5 Q