A
A
Aristarchus2018-04-30 13:50:37
PHP
Aristarchus, 2018-04-30 13:50:37

How to get rid of string() in an array?

The script from the folder takes all files with the .json extension , if it is really .json , then removes the file extension and writes the name (of the user) to the $data['users'] array
And here a problem arose, some string() appeared in the array, here is an example response:

array(2) { [0]=> string(11) "1enderstore" [1]=> string(5) "sport" }

Output via var_dump() How to convert an array to normal form? Namely, in And the most interesting, if converted to json (var_dump(json_encode($data['users']));), then the answer will be:
var_dump($data['users']);
array(2) { [0]=> "1enderstore" [1]=> "sport" }
string(23) "["1enderstore","sport"]"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DemonIa, 2018-04-30
@EnderStore

Maybe I misunderstood the essence of the question, but since you display information through var_dump, in any case it also shows the data type (in your case, string).
You can use this construct to output

echo '<pre>';
print_r(  $data  );
echo '</pre>'

A
Alexander Taratin, 2018-04-30
@Taraflex

This is the output format of var_dump with types.
php.net/manual/en/function.var-dump.php

The function displays structured information about one or more expressions, including their type and value. Arrays and objects are parsed recursively with values ​​indented differently to visually display the structure.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question