1
I have the following code
<?php
while($data = $QuerySearch->fetch(PDO::FETCH_ASSOC)){
$js[] = $data;
}
$r = array();
$arr = array();
foreach($js as $k=>$v){
foreach($v as $col=>$c){
$arr[] = $c;
}
array_push($r, $arr);
}
$r = array_map('htmlentities', $arr);
if(isset($r)){
echo 'Existe<br>';
if(is_array($arr)){
echo 'Tb existe';
}else{
echo 'nao existe arr';
}
}else{
echo 'nao existe';
}
echo print_r($r);
?>
As you can see, the array is being formed, but it does not display the array. When I put one echo
in place of arr[]
it normally displays the data, now I put a echo json_encode($arr);
it gets empty, and in the checks I did above displays like this:
Existe
Não existe arr
I mean, there is $arr[]
but he says it’s not a array()
And this line here:
$arr = '';
at the end offoreach
, she’s converting$arr
instring
nay?– Cahe
@Cahe Really, only when running 1 loop, I need that type, zeroes the Indice pq will create + arrays. to look like arr[0] => data, arr[1] =>data... I put $arr[] = array(); displays an empty array
– Alisson Acioli
@Cahe I gave print_r($arr) and he shows me all the data, but I put json_encode it shows nothing.
– Alisson Acioli
What do you want to do with
$r
? Shouldn’t be the$r
that you check on if/Else below? That line$arr = '';
is erasing the$arr
, take it off.– Sergio
@Sergio did everything you said and when I give
echo json_encode($r)
he does not appear, now I putprint_r($r)
it appears the data I need– Alisson Acioli
And if you do
var_dump($r);
what appears?– Sergio
@Sergio appears the same things as the
print_r
. The strange thing is that the othersjson_encode()
works properly, only I use it like thisjson_encode(array('indice'=>'valor'));
forwardness ofjson_encode($r);
– Alisson Acioli
There should be a kind of answer
{"indice":"valor"}
. You can enter the code related to thisjson_encode
, so you can see how it is doing. Now there is nojson_encode
in the question...– Sergio
Htmlentities also does not support accentuation without passing ISO 8859 encoding parameters... And a detail, please do not modify the original code with error in the question, if you add the corrected below...
– Jader A. Wagner