I am trying to fetch data from MySQL. Because I am still learning PHP and MySQLi, I do not completely understand why this code prints double results with numeric keys too. I need push only string keys with values. Thanks for some direction.
code
if ( $r = $mysqli -> query ( $q ) ) {
${ 'err_css_' . $err_asid } = array ();
while ( $row = mysqli_fetch_array ( $r ) ) {
array_push ( ${ 'err_css_' . $err_asid }, ${ 'err_css_' . $err_asid }[$row['language_asid']]=$row['value'] );
}
print_r ( ${'err_css_' . $err_asid } );
}
result:
Array (
[ces] => background:czech_flag_url;
[0] => background:czech_flag_url; // i dont want numeric key
[eng] => background:english_flag_url;
[1] => background:english_flag_url; // i dont want numeric key
)
fetch_array
populates both numeric and string keys, you're looking forfetch_assoc
.while ( $row = mysqli_fetch_assoc ( $r ) )
, the result is same.why this code prints double results with numeric keys too
this is by default, otherwise you need to pass additional flags infetch_array
for what you really want.$array[$row['language_asid']] = $row['value']