Answer the question
In order to leave comments, you need to log in
How to rearrange an array?
There is an array
$data = array(
array( 'x' => '1', 'y' => '1', 'z' => '1' ),
array( 'x' => '2', 'y ' => '2', 'z' => '2' ),
array( 'x' => '3', 'y' => '3', 'z' => '3' ),
array( ' x' => '4', 'y' => '4', 'z' => '4' )
);
You need to regroup in the form:
$data = array(
'x' => array('1', ..., '99'),
'y' => array('1', ..., '99'),
'z' => array('1', ..., '99')
);
I'm thinking of doing something like this:
$result = array();
foreach($data as $val){
foreach($val as $key => $type)
for ($i=0; $i < count($type); ++$i) {
$result = array($i => $type);
}
}
Answer the question
In order to leave comments, you need to log in
$result = array();
foreach($data as $val) {
foreach($val as $key => $type) {
$result[$key][] = $type;
}
}
Come on, by the third question, will you already learn how to format the code with normal formatting?
And this. As long as you are stuffed with ready-made codes, this "as usual does not work" for you will remain so.
Did not try to look at the result of the work of your hands and redo the code?
why don't you add anything to $result?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question