I have this array
Array ( [0] => Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 [18] => 19 [19] => 20 [20] => 21 [21] => 22 [22] => 23 [23] => 24 [24] => 25 [25] => 26 [26] => 27 [27] => 28 [28] => 29 [29] => 30 ) [1] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 [21] => 1 [22] => 1 [23] => 1 [24] => 1 [25] => 1 [26] => 1 [27] => 1 [28] => 1 [29] => 1 ) [2] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 [21] => 1 [22] => 1 [23] => 1 [24] => 1 [25] => 1 [26] => 1 [27] => 1 [28] => 1 [29] => 1 ) [3] => Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 1 [4] => 1 [5] => 1 [6] => 1 [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 [21] => 1 [22] => 1 [23] => 1 [24] => 1 [25] => 1 [26] => 1 [27] => 1 [28] => 1 [29] => 1 ) ) )
I can access the data like this:
print_r($ps[0][0]);
print_r($ps[0][1]);
print_r($ps[0][2]);
print_r($ps[0][3]);
How can I separate it in a foreach loop I mean each second key?
I solved it like this:
for ($i = 0 ; $i < count($ps[0]); $i++) {
foreach ($ps[0][$i] as $p) {
echo $p.'<br/>';
}
}
Since you showed an attempt (in an answer), you can use two foreach:
foreach($ps[0] as $array) {
foreach($array as $p) {
echo "$p<br/>";
}
}
Related
i have following array format in php:
Array
(
[item] => Array
(
[0] => RSJ Pole 116 x100 ,11 Mtr
[1] => RSJ Pole 116 x100 ,10 Mtr
[2] => RSJ Pole 116 x 100, 9 Mtr
[3] => RSJ Pole 116 x 100, 8 Mtr
[4] => Line Length in Kms
[5] => RSJ 125x70, 9 m long
[6] => PSC Pole 9 Mtr
[7] => PSC Pole 8 Mtr
[8] => Conductor ACSR Dog 0.1
[9] => Conductor ACSR Rabbit 55 Sq.mm
[10] => Conductor ACSR Raccon 80 Sq.mm
[11] => Conductor Weisel 34 Sq.mm
[12] => Conductor Ant
[13] => Conductor Gnat
[14] => New DTC 100 KVA
[15] => New DTC 63 KVA
[16] => BPL Connection
[17] => SDT
)
[scope] => Array
(
[0] => 1172
[1] => 6637
[2] => 854
[3] => 4
[4] => 653.71
[5] => 558.9
[6] => 5864
[7] => 820
[8] => 745385
[9] => 1188772.2
[10] => 327600
[11] => 18900
[12] => 232015.9
[13] => 70634.3
[14] => 344
[15] => 54
[16] => 13632
[17] => 37
)
[till] => Array
(
[0] => 3
[1] => 4
[2] => 4
[3] => 6
[4] => 5
[5] => 5
[6] => 5
[7] => 5
[8] => 2
[9] => 5
[10] => 5
[11] => 5
[12] => 5
[13] => 5
[14] => 5
[15] => 5
[16] => 5
[17] => 2
)
[value] => Array
(
[0] => 4
[1] => 7
[2] => 1
[3] => 2
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
)
[submit] => submit
)
i want to concatenate with "_" operator before submitting or while inserting into database field for eg. 1172_3_4
You can array_map the 3 arrays
$arr = .... //Your array here
$results = array_map(function($s, $t, $v) {
return $s . "_" . $t . "_" . $v;
}, $arr['scope'], $arr['till'], $arr['value']);
echo "<pre>";
print_r( $results );
echo "</pre>";
$results will have the value:
Array
(
[0] => 1172_3_4
[1] => 6637_4_7
[2] => 854_4_1
[3] => 4_6_2
[4] => 653.71_5_
[5] => 558.9_5_
[6] => 5864_5_
[7] => 820_5_
[8] => 745385_2_
[9] => 1188772.2_5_
[10] => 327600_5_
[11] => 18900_5_
[12] => 232015.9_5_
[13] => 70634.3_5_
[14] => 344_5_
[15] => 54_5_
[16] => 13632_5_
[17] => 37_2_
)
Doc: array_map()
Implement the loop at main array and increment in $i then concatenate $array_variable['scope'][$i].'_'.$array_variable['till'][$i].'_'.$array_variable['value'][$i].
I want to parse the following excel file using PHP Excel Library and put the data into email templates(PFA).
Here goes the corresponding code for parsing the data:
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($target_file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($target_file);
} catch(Exception $e) {
die('Error loading file "'.pathinfo($target_file,PATHINFO_BASENAME).'": '.$e->getMessage());
}
// Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){
$val=array();
for ($col = 0; $col < $highestColumn; ++ $col) {
$cell = $worksheet->getCellByColumnAndRow($col, $row);
$val[] = $cell->getValue();
}
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
// Insert row data array into your database of choice here
print_r(array_values($rowData));
The output is:
Array ( [0] => Array ( [0] => S No [1] => Hotel Name [2] => Room Category [3] => GuestHouse Id [4] => Hotel Email [5] => City [6] => state [7] => 2nd Feb [8] => 3rd Feb [9] => 4th Feb [10] => 5th Feb [11] => 6th Feb [12] => 7th Feb [13] => 8th Feb [14] => 9th Feb [15] => 10th Feb [16] => 11th Feb [17] => 12th Feb [18] => 13th Feb [19] => 14th Feb [20] => 15th Feb ) ) Array ( [0] => Array ( [0] => 1 [1] => Hotel 1 [2] => All [3] => 19 [4] => a#y.com [5] => Ahmedabad [6] => Gujarat [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Standard [3] => [4] => [5] => [6] => [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Superior [3] => [4] => [5] => [6] => [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 [20] => 0 ) ) Array ( [0] => Array ( [0] => 2 [1] => Hotel 2 [2] => All [3] => 18 [4] => y#a.in [5] => Mumbai [6] => Maharashtra [7] => 2 [8] => 3 [9] => 4 [10] => 4 [11] => 4 [12] => 4 [13] => 4 [14] => 4 [15] => 4 [16] => 4 [17] => 4 [18] => 4 [19] => 2 [20] => 3 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Standard [3] => [4] => [5] => [6] => [7] => 0 [8] => 1 [9] => 2 [10] => 2 [11] => 2 [12] => 2 [13] => 2 [14] => 2 [15] => 2 [16] => 2 [17] => 2 [18] => 2 [19] => 0 [20] => 1 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Superior [3] => [4] => [5] => [6] => [7] => 2 [8] => 2 [9] => 2 [10] => 2 [11] => 2 [12] => 2 [13] => 2 [14] => 2 [15] => 2 [16] => 2 [17] => 2 [18] => 2 [19] => 2 [20] => 2 ) ) Array ( [0] => Array ( [0] => 3 [1] => Hotel 3 [2] => All [3] => 199 [4] => m#mm.co.in [5] => Amravati [6] => Maharashtra [7] => 20 [8] => 20 [9] => 20 [10] => 20 [11] => 20 [12] => 20 [13] => 20 [14] => 20 [15] => 20 [16] => 20 [17] => 20 [18] => 20 [19] => 20 [20] => 20 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Standard [3] => [4] => [5] => [6] => [7] => 10 [8] => 10 [9] => 10 [10] => 10 [11] => 10 [12] => 10 [13] => 10 [14] => 10 [15] => 10 [16] => 10 [17] => 10 [18] => 10 [19] => 10 [20] => 10 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Superior [3] => [4] => [5] => [6] => [7] => 10 [8] => 10 [9] => 10 [10] => 10 [11] => 10 [12] => 10 [13] => 10 [14] => 10 [15] => 10 [16] => 10 [17] => 10 [18] => 10 [19] => 10 [20] => 10 ) ) Array ( [0] => Array ( [0] => 4 [1] => Hotel 4 [2] => All [3] => 35 [4] => a#c.net [5] => Lonavala [6] => Maharashtra [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 ) ) Array ( [0] => Array ( [0] => [1] => [2] => Villa [3] => [4] => [5] => [6] => [7] => 1 [8] => 1 [9] => 1 [10] => 1 [11] => 1 [12] => 1 [13] => 1 [14] => 1 [15] => 1 [16] => 1 [17] => 1 [18] => 1 [19] => 1 [20] => 1 ) )
Now, what I want is after I have have this multi-dimensional associative array in place, I want to extract the data in such a way so as to get this expected output.
This is the place where I am stuck. I am unable to extract data properly because on one hand I need to skip empty null fields whereas on the other hand I need to skip the "All" field. Any help or suggestion is highly appreciated.
Hi I have a collection of numbers and I want to find the most occurring number and then the 2nd most occurring and then the third most occurring till 10 and store the result in a array.
The collection looks like this
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => 12
[1] => 194
[2] => 241
[3] => 4
[4] => 29
[5] => 4
[6] => 12
[7] => 15
[8] => 21
[9] => 31
[10] => 281
[11] => 4
[12] => 6
[13] => 4
[14] => 2
[15] => 6
[16] => 4
[17] => 4
[18] => 4
[19] => 15
[20] => 4
[21] => 4
[22] => 13
[23] => 10
[24] => 8
[25] => 8
[26] => 2
[27] => 2
[28] => 2
[29] => 17
[30] => 4
[31] => 20
[32] => 2
[33] => 4
[34] => 20
[35] => 6
)
)
So I want to find the most occurring one and so on till 10th most occurring number.
use array_count_values, here is your reference link http://www.w3schools.com/php/func_array_count_values.asp
<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>
Output
Array ( [A] => 2 [Cat] => 1 [Dog] => 2 )
I have an array of calendar dates, and an multidimensional array of reports where the key to the reports is the date
Array of calendar dates structure
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
)
And my Array of reports structure
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
Now i want to loop through the calendar and for every value in the calendar array (the date) that matches the key of the report array (eg the date), i want to attach the reports to calendar value and use the value calendar as a key to the reports other wise i want to add a string saying no reports done.
heres how i though i might go about
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar[][$cal] = $rdate;
}
}
}
this however just adds them to the end of the calendar array and not where the calendar value and report key match.
Like so
Array
(
[1] => 2014-05-01
[2] => 2014-05-02
[3] => 2014-05-03
[4] => 2014-05-04
[5] => 2014-05-05
[6] => 2014-05-06
[7] => 2014-05-07
[8] => 2014-05-08
[9] => 2014-05-09
[10] => 2014-05-10
[11] => 2014-05-11
[12] => 2014-05-12
[13] => 2014-05-13
[14] => 2014-05-14
[15] => 2014-05-15
[16] => 2014-05-16
[17] => 2014-05-17
[18] => 2014-05-18
[19] => 2014-05-19
[20] => 2014-05-20
[21] => 2014-05-21
[22] => 2014-05-22
[23] => 2014-05-23
[24] => 2014-05-24
[25] => 2014-05-25
[26] => 2014-05-26
[27] => 2014-05-27
[28] => 2014-05-28
[29] => 2014-05-29
[30] => 2014-05-30
[31] => 2014-05-31
[32] => Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
)
[33] => Array
(
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
)
[34] => Array
(
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
)
[35] => Array
(
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
)
[36] => Array
(
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
)
[37] => Array
(
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
)
[38] => Array
(
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
)
[39] => Array
(
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
)
[40] => Array
(
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
)
)
instead of this i would like this
Array (
[1] => 2014-05-01 => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
...........
)
I think where i have been bashing my head against a wall i cant see the woods from the trees.
Any help would be grand or guidence would be grand.
regards Mike
So by writing this out i must of figured it out so it actually helped me just by forming the question, this is what i changed
foreach ($dates_month_with_reports as $cal)
{
foreach ($reportdates as $key => $rdate)
{
if ($key == $cal)
{
//took away the extra array
$dates_month_with_reports[$cal] = $rdate;
}
}
}
and in the calendar array i added the date to the key aswell which now gives me this
Array
(
[2014-05-01] => Array
(
[0] => 16
[1] => 17
[2] => 18
[3] => 20
[4] => 21
[5] => 22
[6] => 15
[7] => 14
[8] => 13
[9] => 1
[10] => 3
[11] => 4
[12] => 5
[13] => 12
)
[2014-05-02] => 2014-05-02
[2014-05-03] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
[4] => 40
)
[2014-05-04] => 2014-05-04
[2014-05-05] => 2014-05-05
[2014-05-06] => 2014-05-06
[2014-05-07] => 2014-05-07
[2014-05-08] => 2014-05-08
[2014-05-09] => 2014-05-09
[2014-05-10] => 2014-05-10
[2014-05-11] => Array
(
[0] => 2
[1] => 5
[2] => 4
[3] => 3
[4] => 7
[5] => 8
[6] => 9
[7] => 10
[8] => 6
[9] => 1
)
[2014-05-12] => 2014-05-12
[2014-05-13] => 2014-05-13
[2014-05-14] => 2014-05-14
[2014-05-15] => 2014-05-15
[2014-05-16] => 2014-05-16
[2014-05-17] => Array
(
[0] => 3
[1] => 10
[2] => 9
[3] => 8
[4] => 7
[5] => 6
[6] => 2
[7] => 5
[8] => 4
[9] => 1
)
[2014-05-18] => Array
(
[0] => 4
[1] => 5
[2] => 3
[3] => 1
)
[2014-05-19] => Array
(
[0] => 5
[1] => 4
[2] => 3
[3] => 1
)
[2014-05-20] => Array
(
[0] => 1
[1] => 9
[2] => 8
[3] => 7
[4] => 6
[5] => 2
[6] => 5
[7] => 4
[8] => 3
[9] => 10
)
[2014-05-21] => 2014-05-21
[2014-05-22] => 2014-05-22
[2014-05-23] => 2014-05-23
[2014-05-24] => 2014-05-24
[2014-05-25] => 2014-05-25
[2014-05-26] => Array
(
[0] => 1
[1] => 3
[2] => 4
[3] => 5
)
[2014-05-27] => Array
(
[0] => 10
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 9
[6] => 1
[7] => 6
[8] => 8
[9] => 7
)
[2014-05-28] => 2014-05-28
[2014-05-29] => 2014-05-29
[2014-05-30] => 2014-05-30
[2014-05-31] => 2014-05-31
)
I appologize for wasting your time i didnt mean to, but after i wrote the question a figured it out.
$calendar1 = array();
foreach ($calendar as $cal)
{
foreach ($report as $key => $rdate)
{
if ($key == $cal)
{
$calendar1[][$cal] = $rdate;
}
}
}
I have an array like this
Array
(
[0] => 125 c.c.
[1] => Array
(
[0] => AK 125 SL
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
[2] => Array
(
[0] => EVO 125 NE
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
[3] => 150 c.c.
[4] => Array
(
[0] => EVO 150 NE
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
[5] => Array
(
[0] => RXT 150
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
)
I want to format it in a way so it ends up like this:
Array
(
[125 c.c.] => Array
(
[0]=>Array
(
[0] => AK 125 SL
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
[1]=> Array
(
[0] => EVO 125 NE
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
)
[150 c.c.] =>
ARRAY
(
[0] => Array
(
[0] => EVO 150 NE
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
[1] => Array
(
[0] => RXT 150
[1] => 12/13
[2] => R
[3] => 1201X
[4] => L
[5] => FX22,0
[6] => 220
[7] => 58
[8] => 4
[9] => 3
[10] => 8,5
[11] => Drum
[12] => -
[13] => -
[14] => -
[15] => -
[16] => -
[17] => -
[18] => -
)
)
)
Currently I've no idea any help would be greatly appreciated.
foreach($array as $val) {
if(!is_array($val))
{
$finalArray[go here as key]=if not then Go here as value to current key;
}
}
$currentKey = '';
$newArray = array();
foreach ($array as $val) {
if (!is_array($val)) {
$currentKey = $val;
} else {
if (isset($newArray[$currentKey]) && is_array($newArray[$currentKey])) {
$newArray[$currentKey][] = $val;
} else {
$newArray[$currentKey] = array($val);
}
}
}
I hope you understand what is happening here?
And of course it'll work only with arrays like first from your question.