PHP code example of iteks / laravel-json
1. Go to this page and download the library: Download iteks/laravel-json library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iteks / laravel-json example snippets
use Iteks\Support\Facades\Json;
$collection = Json::toCollection(database_path('data/test.json'));
// Iterate over the collection
foreach ($collection as $item) {
// Access properties like in any Laravel collection
echo $item->get('border');
}
$collection = Json::toCollection(database_path('data/test.json'), 'border');
$array = Json::toArray(database_path('data/test.json'));
// Access the array directly
foreach ($array as $item) {
echo $item['border'];
}
$array = Json::toArray(database_path('data/test.json'), 'border');
sh
Illuminate\Support\Collection {#298 ▼
#items: array:3 [▼
0 =>
Illuminate\Support\Collection {#299 ▼
#items: array:3 [▼
"border" => "3px solid white"
"coordinates" => array:2 [▼
0 => 51.70696
1 => 40.34103
]
"password" => "xXeagle-*******"
]
#escapeWhenCastingToString: false
}
1 =>
Illuminate\Support\Collection {#300 ▼
#items: array:3 [▼
"border" => "1px dotted amber"
"coordinates" => array:2 [▼
0 => 11.80583
1 => 108.05094
]
"password" => "xXmeerkat-******"
]
#escapeWhenCastingToString: false
}
2 =>
Illuminate\Support\Collection {#301 ▼
#items: array:3 [▼
"border" => "4px dotted gray"
"coordinates" => array:2 [▼
0 => 116.82882
1 => 74.57905
]
"password" => "xXcat-*******"
]
#escapeWhenCastingToString: false
}
]
#escapeWhenCastingToString: false
}
sh
Illuminate\Support\Collection {#297 ▼
#items: array:3 [▼
0 => "3px solid white"
1 => "1px dotted amber"
2 => "4px dotted gray"
]
#escapeWhenCastingToString: false
}
sh
array:3 [▼
0 => array:3 [▼
"border" => "3px solid white"
"coordinates" => array:2 [▼
0 => 51.70696
1 => 40.34103
]
"password" => "xXeagle-*******"
]
1 => array:3 [▼
"border" => "1px dotted amber"
"coordinates" => array:2 [▼
0 => 11.80583
1 => 108.05094
]
"password" => "xXmeerkat-******"
]
2 => array:3 [▼
"border" => "4px dotted gray"
"coordinates" => array:2 [▼
0 => 116.82882
1 => 74.57905
]
"password" => "xXcat-*******"
]
]
sh
array:3 [▼
0 => "3px solid white"
1 => "1px dotted amber"
2 => "4px dotted gray"
]