Last active
February 13, 2022 11:10
-
-
Save umidjons/6349938 to your computer and use it in GitHub Desktop.
Read JSON string from file, convert PHP stdClass object to array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// file_get_contents - get file content (JSON string in it) | |
// json_decode - decode JSON string to PHP object | |
// get_object_vars - convert PHP object to array | |
$data = get_object_vars( json_decode( file_get_contents( 'data.txt' ) ) ); | |
$data = array_slice( $data, 0, 10 ); // now you can array functions | |
echo json_encode( $data ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment