Answer the question
In order to leave comments, you need to log in
Is it possible to do a similar transformation of an array without a loop?
Good day!
I am making a conclusion from the base to the array, but the presence of the second cycle is sad, tell me please, is it possible to do without it in order to increase performance?
function mysql_query_array($query, $error="error: mysql_query_array"){
$r = mysql_query($query) or die($error);
$row = mysql_fetch_assoc($r);
$row_key = array_keys($row);
$j=0;
do{
for($i=0; $i<count($row_key); $i++){
$row_array[$row_key[$i]][$j] = $row[$row_key[$i]];
}
$j++;
} while($row = mysql_fetch_assoc($r));
unset($row);
return $row_array;
}
Answer the question
In order to leave comments, you need to log in
And what - productivity is directly strongly affected?
It was a rhetorical question.
The code shows the victim of Popov's video courses. On this, in general, the question can be closed.
Nothing will help you anymore. Regardless of whether unset is needed here or not.
In essence - this function should not exist at all in any form.
Why did you need to change the keys at all? To write the same two loops on the output to expand the array back?
use pdo and don't teach kgo in a priestly way! at least you will learn how to write,
I understand that you need to process each line from the database in turn. if yes then here
$b = mysql_query("SELECT ip FROM svc ");
while ($eastb = mysql_fetch_array($b))
{
echo''.$eastb.'<br>';
}
My advice is to register on Habré and read a lot.
Also take yii framework or yii2 on hand
If the task is to convert the following result:
id, name, var
1, name1, 10
2, name2, 10
3, name3, 30
into this:
array(
id => array(0 => 1,0 => 2,0 => 3),
name => array(0 => name1,0 => name2,0 => name3),
var => array(0 => 10, 0 => 20, 0 => 30),
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question