2
How to organize the index of the 2nd dimension array?
Seeking
$stmt = getConn()->query("SELECT hash,id,quantidade FROM pergaminhos");
$resp = $stmt->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_COLUMN);
reply
Array
(
[1] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[2] => Array
(
[0] => 4
)
)
desired response
Array
(
[1] => Array
(
[1] => 1
[2] => 1
[3] => 1
)
[2] => Array
(
[4] => 1
)
)
written form for better understanding
Array
(
[valor_do_hash] => Array
(
[valor_do_id] => valor_do_quantidade
[valor_do_id] => valor_do_quantidade
[valor_do_id] => valor_do_quantidade
)
[valor_do_hash] => Array
(
[valor_do_id] => valor_do_quantidade
)
)
But the goal is each key of each sub-array to increase in
1
? Or is there any case where that is not true? And what is the intention in doing so? It would not be better when you use the change you want to the key before modifying ?– Isac
@Isac actually, he is already getting the result, so much so that I told him that, as he already has the result the correct is to delete my answer. For me to be able to delete the answer, he must uncheck it as correct/accepted.
– NoobSaibot