Home>
When the following sequence exists
$testarr [] = array (
'namae' =>'Tanaka',
'favorite' =>'tuna'
);
$testarr [] = array (
'namae' =>'Tanaka',
'favorite' =>'Hamachi'
);
$testarr [] = array (
'namae' =>'Tanaka',
'favorite' =>'how much'
);
$testarr [] = array (
'namae' =>'Tanaka',
'favorite' =>'salmon'
);
$testarr [] = array (
'namae' =>'Tanaka',
'favorite' =>'sardines'
);
$testarr [] = array (
'namae' =>'Matsuda',
'favorite' =>'shishamo'
);
$testarr [] = array (
'namae' =>'Matsuda',
'favorite' =>'mackerel'
);
$testarr [] = array (
'namae' =>'Matsuda',
'favorite' =>'Thailand'
);
$testarr [] = array (
'namae' =>'Matsuda',
'favorite' =>'Buri'
);
$testarr [] = array (
'namae' =>'Matsuda',
'favorite' =>'Kalei'
);
I created a new array as one array with the samename, but I am not sure how to do it.
I want to create a new array as shown below.
$kanseilist = array (
0 =>
array (
'name' =>'Tanaka'
array (
0 =>'tuna',
1 =>'Hamachi',
2 =>'how much',
3 =>'Salmon',
4 =>'sardines',
),
1 =>
array (
'name' =>'Matsuda'
array (
0 =>'shishamo',
1 =>'mackerel',
2 =>'Thailand',
3 =>'Buri',
4 =>'Kalei',
),
);
I tried the following, but I was struggling because I couldn't distribute them well.
$kanseilist = array ();
for ($j = 0;$j<count ($testarr);$j ++) {
if ($testarr [$i] ['name'] == $testarr [$j] ['name']) {
$kanseilist [] = array (
'name' =>$testarr [$j] ['name'],
'shohi' =>$testarr [$j] ['favorite']
);
}
}
}
-
Answer # 1
Related articles
- about php multidimensional arrays
- php - use array_filter for multidimensional associative arrays
- i want to group associative arrays by specified key in php
- python - i want to organize data using two arrays
- [php] about combining associative arrays
- i want to verify php multi-dimensional associative array
- i want to add as many parent layers as there are arrays in php
- php - to get only the values of a multidimensional array as a list
- [php] extracting a specific part from a multidimensional array
- [php] multidimensional array and associative array
- php - i want to create an array by extracting a multidimensional array with regular expressions
- php - how to get multidimensional json data with javascript
- php - i want to output a multidimensional array
- php - i want to get the number of arrays in the repeating field of advanced custom fields
- php - i want to loop a multidimensional array and display it on a table
- i want to combine two associative arrays in php
- php - i want to give the key value of a multidimensional array to the value of the array
- php - how to combine data arrays
- calculation between php arrays
- i would like to know the best way to pass values such as numbers and arrays obtained with php to javascript
Trends