Working with multiple array in PHP - php

I have an array like this :
$optionarray:
array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [2]=> array(3) { [0]=> string(19) "Formation" [1]=> string(1) "1" [2]=> string(1) "0" } }
$dataarray:
array(2) { [0]=> array(3) { [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" } [1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" } }
$fullarray:
array(5) { [0]=> array(3) { [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" } [1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" } [2]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [2]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" } } [3]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" } [1]=> array(3) { [0]=> string(19) "Formation" [1]=> string(1) "1" [2]=> string(1) "0" } [2]=> NULL } [4]=> array(3) { [0]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" } [1]=> NULL [2]=> NULL } }
My fullarray has not a unique structure , I want just to add $optionarray to $dataarray and iterate on $fullarray
My code :
$data[0] = array('Physical room', $nbprice, $totalprice);
$data[1] = array('user desk', $nbuser, $totaluserprice );
$i=2;
for($j=0;$j<count($optionsdata);$j++){
$data[$i]=array($optionsdata[$j],$optionsdata[$j+1],$optionsdata[$j+2]);
$i=$i+1;
}
How can I proceed for create my $fullarray properly for iterate and display each value ?
Expected output:
array(5){
[0]=>array(3){ [0]=> string(23) "Physical room" [1]=> int(1) [2]=> string(7) "12,00 €" }
[1]=> array(3) { [0]=> string(26) "user desk" [1]=> int(4) [2]=> string(7) "40,00 €" }
[2]=> array(3) { [0]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" }
[3]=> array(3) { [0]=> string(15) "Extension" [1]=> string(1) "1" [2]=> string(2) "10" }
[4]=> array(3) { [0]=> string(19) "Formation " [1]=> string(1) "1" [2]=> string(1) "0" }
}

Related

PHP: Convert Google Sheets result object to simple array

I've google sheet with this data:
I'm pulling it from google drive with simple code:
$ranges = [
'Price_1'
];
$params = array(
'ranges' => $ranges
);
$response = $service->spreadsheets_values->batchGet($spreadsheetId, $params);
The response is a complicated object:
object(Google_Service_Sheets_BatchGetValuesResponse)#58 (8) { ["collection_key":protected]=> string(11) "valueRanges" ["spreadsheetId"]=> string(44) "1BQpKLuvlaVeGqIqoGUOynF9IZ5C3zK6gagZiRJO1UEU" ["valueRangesType":protected]=> string(32) "Google_Service_Sheets_ValueRange" ["valueRangesDataType":protected]=> string(5) "array" ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } ["valueRanges"]=> array(1) { [0]=> object(Google_Service_Sheets_ValueRange)#67 (7) { ["collection_key":protected]=> string(6) "values" ["majorDimension"]=> string(4) "ROWS" ["range"]=> string(14) "Price_1!E2:E74" ["values"]=> array(65) { [0]=> array(1) { [0]=> string(2) "28" } [1]=> array(1) { [0]=> string(2) "14" } [2]=> array(1) { [0]=> string(1) "0" } [3]=> array(0) { } [4]=> array(1) { [0]=> string(2) "55" } [5]=> array(1) { [0]=> string(2) "28" } [6]=> array(1) { [0]=> string(1) "0" } [7]=> array(0) { } [8]=> array(0) { } [9]=> array(0) { } [10]=> array(0) { } [11]=> array(0) { } [12]=> array(0) { } [13]=> array(0) { } [14]=> array(0) { } [15]=> array(0) { } [16]=> array(0) { } [17]=> array(0) { } [18]=> array(0) { } [19]=> array(0) { } [20]=> array(1) { [0]=> string(2) "59" } [21]=> array(1) { [0]=> string(2) "49" } [22]=> array(0) { } [23]=> array(1) { [0]=> string(2) "38" } [24]=> array(1) { [0]=> string(2) "38" } [25]=> array(0) { } [26]=> array(1) { [0]=> string(2) "37" } [27]=> array(1) { [0]=> string(2) "25" } [28]=> array(1) { [0]=> string(1) "0" } [29]=> array(0) { } [30]=> array(1) { [0]=> string(2) "79" } [31]=> array(1) { [0]=> string(2) "99" } [32]=> array(0) { } [33]=> array(1) { [0]=> string(2) "75" } [34]=> array(1) { [0]=> string(2) "99" } [35]=> array(0) { } [36]=> array(1) { [0]=> string(2) "79" } [37]=> array(1) { [0]=> string(2) "99" } [38]=> array(0) { } [39]=> array(1) { [0]=> string(3) "160" } [40]=> array(1) { [0]=> string(3) "190" } [41]=> array(0) { } [42]=> array(0) { } [43]=> array(0) { } [44]=> array(0) { } [45]=> array(0) { } [46]=> array(0) { } [47]=> array(0) { } [48]=> array(0) { } [49]=> array(0) { } [50]=> array(0) { } [51]=> array(0) { } [52]=> array(1) { [0]=> string(2) "33" } [53]=> array(0) { } [54]=> array(1) { [0]=> string(2) "59" } [55]=> array(1) { [0]=> string(2) "34" } [56]=> array(1) { [0]=> string(1) "0" } [57]=> array(0) { } [58]=> array(1) { [0]=> string(2) "29" } [59]=> array(1) { [0]=> string(2) "14" } [60]=> array(1) { [0]=> string(1) "0" } [61]=> array(0) { } [62]=> array(1) { [0]=> string(2) "37" } [63]=> array(1) { [0]=> string(2) "25" } [64]=> array(1) { [0]=> string(1) "0" } } ["internal_gapi_mappings":protected]=> array(0) { } ["modelData":protected]=> array(0) { } ["processed":protected]=> array(0) { } } } }
and var_dump($response->getValueRanges()[0]['values']); gives this result:
array(74) { [0]=> array(5) { [0]=> string(2) "ID" [1]=> string(10) "Ticket for" [2]=> string(9) "Excursion" [3]=> string(8) "Duration" [4]=> string(14) "Price (Brutto)" } [1]=> array(5) { [0]=> string(3) "01A" [1]=> string(13) "adult ( 12+ )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "28" } [2]=> array(5) { [0]=> string(3) "01B" [1]=> string(18) "child ( age 5-11 )" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(2) "14" } [3]=> array(5) { [0]=> string(3) "01C" [1]=> string(18) "toodler ( age 0-4)" [2]=> string(9) "Catamaran" [3]=> string(2) "2h" [4]=> string(1) "0" } [4]=> array(0) { } [5]=> array(5) { [0]=> string(3) "02A" [1]=> string(13) "adult, age 8+" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "55" } [6]=> array(5) { [0]=> string(3) "02B" [1]=> string(14) "child, age 3-7" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(2) "28" } [7]=> array(5) { [0]=> string(3) "02C" [1]=> string(16) "toodler, age 0-2" [2]=> string(17) "Luxurt yacht trip" [3]=> string(2) "3h" [4]=> string(1) "0" } [8]=> array(0) { } [9]=> array(3) { [0]=> string(3) "03A" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [10]=> array(3) { [0]=> string(3) "03B" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [11]=> array(3) { [0]=> string(3) "03C" [1]=> string(0) "" [2]=> string(8) "Sailboat" } [12]=> array(0) { } [13]=> array(3) { [0]=> string(3) "04A" [1]=> string(0) "" [2]=> string(9) "Submarine" } [14]=> array(3) { [0]=> string(3) "04B" [1]=> string(0) "" [2]=> string(9) "Submarine" } [15]=> array(3) { [0]=> string(3) "04C" [1]=> string(0) "" [2]=> string(9) "Submarine" } [16]=> array(0) { } [17]=> array(3) { [0]=> string(3) "05A" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [18]=> array(3) { [0]=> string(3) "05B" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [19]=> array(3) { [0]=> string(3) "05C" [1]=> string(0) "" [2]=> string(13) "JetSki safari" } [20]=> array(0) { } [21]=> array(5) { [0]=> string(3) "06A" [1]=> string(9) "fisherman" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "59" } [22]=> array(5) { [0]=> string(3) "06B" [1]=> string(9) "spectator" [2]=> string(7) "Fishing" [3]=> string(2) "4h" [4]=> string(2) "49" } [23]=> array(0) { } [24]=> array(5) { [0]=> string(3) "07A" [1]=> string(5) "adult" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [25]=> array(5) { [0]=> string(3) "07B" [1]=> string(13) "child, age 6+" [2]=> string(12) "Parascending" [3]=> string(5) "30min" [4]=> string(2) "38" } [26]=> array(0) { } [27]=> array(5) { [0]=> string(3) "08A" [1]=> string(14) "adult, age 12+" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "37" } [28]=> array(5) { [0]=> string(3) "08B" [1]=> string(15) "child, age 3-11" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(2) "25" } [29]=> array(5) { [0]=> string(3) "08C" [1]=> string(16) "toodler, age 0-1" [2]=> string(9) "Siam Park" [3]=> string(0) "" [4]=> string(1) "0" } [30]=> array(0) { } [31]=> array(5) { [0]=> string(3) "09A" [1]=> string(17) "flight from 800m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "15min" [4]=> string(2) "79" } [32]=> array(5) { [0]=> string(3) "09B" [1]=> string(18) "flight from 1000m." [2]=> string(18) "Paragliding tandem" [3]=> string(5) "25min" [4]=> string(2) "99" } [33]=> array(0) { } [34]=> array(5) { [0]=> string(3) "10A" [1]=> string(21) "Single (for 1 person)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "75" } [35]=> array(5) { [0]=> string(3) "10B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(27) "Quad safari Forest explorer" [3]=> string(2) "3h" [4]=> string(2) "99" } [36]=> array(0) { } [37]=> array(5) { [0]=> string(3) "11A" [1]=> string(21) "Single (for 1 person)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "79" } [38]=> array(5) { [0]=> string(3) "11B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(24) "Quad Safari - Teide tour" [3]=> string(2) "4h" [4]=> string(2) "99" } [39]=> array(0) { } [40]=> array(5) { [0]=> string(3) "12A" [1]=> string(21) "Single (for 1 person)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "160" } [41]=> array(5) { [0]=> string(3) "12B" [1]=> string(22) "Double (for 2 persons)" [2]=> string(15) "Buggy adventure" [3]=> string(2) "3h" [4]=> string(3) "190" } [42]=> array(0) { } [43]=> array(3) { [0]=> string(3) "13A" [1]=> string(0) "" [2]=> string(8) "Trekking" } [44]=> array(3) { [0]=> string(3) "13B" [1]=> string(0) "" [2]=> string(8) "Trekking" } [45]=> array(3) { [0]=> string(3) "13C" [1]=> string(0) "" [2]=> string(8) "Trekking" } [46]=> array(0) { } [47]=> array(3) { [0]=> string(3) "14A" [1]=> string(0) "" [2]=> string(7) "Karting" } [48]=> array(3) { [0]=> string(3) "14B" [1]=> string(0) "" [2]=> string(7) "Karting" } [49]=> array(3) { [0]=> string(3) "14C" [1]=> string(0) "" [2]=> string(7) "Karting" } [50]=> array(0) { } [51]=> array(3) { [0]=> string(3) "15A" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [52]=> array(3) { [0]=> string(3) "15B" [1]=> string(0) "" [2]=> string(11) "Jungle park" } [53]=> array(5) { [0]=> string(3) "15C" [1]=> string(0) "" [2]=> string(11) "Jungle park" [3]=> string(0) "" [4]=> string(2) "33" } [54]=> array(0) { } [55]=> array(5) { [0]=> string(3) "16A" [1]=> string(14) "adult, age 12+" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "59" } [56]=> array(5) { [0]=> string(3) "16B" [1]=> string(15) "child, age 2-11" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(2) "34" } [57]=> array(5) { [0]=> string(3) "16C" [1]=> string(16) "toodler, age 0-1" [2]=> string(16) "La Gomera island" [3]=> string(12) "7:40 - 18:00" [4]=> string(1) "0" } [58]=> array(0) { } [59]=> array(5) { [0]=> string(3) "17A" [1]=> string(14) "adult, age 12+" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "29" } [60]=> array(5) { [0]=> string(3) "17B" [1]=> string(15) "child, age 2-11" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(2) "14" } [61]=> array(5) { [0]=> string(3) "17C" [1]=> string(16) "toodler, age 0-1" [2]=> string(31) "Santa Cruz/ La Laguna/ Taganana" [3]=> string(1) "?" [4]=> string(1) "0" } [62]=> array(0) { } [63]=> array(5) { [0]=> string(3) "18A" [1]=> string(14) "adult, age 12+" [2]=> string(11) "Loro parque" [3]=> string(12) "8:30 - 18:45" [4]=> string(2) "37" } [64]=> array(5) { [0]=> string(3) "18B" [1]=> string(15) "child, age 6-11" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(2) "25" } [65]=> array(5) { [0]=> string(3) "18C" [1]=> string(16) "toodler, age 0-1" [2]=> string(11) "Loro parque" [3]=> string(0) "" [4]=> string(1) "0" } [66]=> array(0) { } [67]=> array(3) { [0]=> string(3) "19A" [1]=> string(0) "" [2]=> string(9) "Antologia" } [68]=> array(3) { [0]=> string(3) "19B" [1]=> string(0) "" [2]=> string(9) "Antologia" } [69]=> array(3) { [0]=> string(3) "19C" [1]=> string(0) "" [2]=> string(9) "Antologia" } [70]=> array(0) { } [71]=> array(3) { [0]=> string(3) "20A" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [72]=> array(3) { [0]=> string(3) "20B" [1]=> string(0) "" [2]=> string(13) "Medieval show" } [73]=> array(3) { [0]=> string(3) "20C" [1]=> string(0) "" [2]=> string(13) "Medieval show" } }
And:
for($i = 1; $i < 5; $i++) {
print_r ($response->getValueRanges()[0]['values'][$i]);
}
Gives: Array ( [0] => 01A [1] => adult ( 12+ ) [2] => Catamaran [3] => 2h [4] => 28 ) Array ( [0] => 01B [1] => child ( age 5-11 ) [2] => Catamaran [3] => 2h [4] => 14 ) Array ( [0] => 01C [1] => toodler ( age 0-4) [2] => Catamaran [3] => 2h [4] => 0 ) Array ( )
In result I need a simple array, which will hold a key[row id], the ID from from ID row and price from last row, somethig like this: $result[$i] = unique_id=1, ID=01A, price=28
How it could be achieved?
So after getting the data for google sheet with:
$arr = $response->getValueRanges()[0]['values'];
You can use this simple for loop to get the data as you need:
// notice start from 1 to avoid the headers
for($i = 1; $i < count($arr); $i++) {
$res[$i] = array("unique_id" => $i, "ID" => $arr[$i][0], "price" => $arr[$i][4]);
}
Now $res will contain you structure.

Removing duplicate data in a multi dimension array (associative array)

I have three keys pointing to value of type array, in those array values I have duplicate values. How can I remove them?
array(3) {
["rock"]=>
array(4) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["title"]=>
string(15) "Teleman Tickets"
["location"]=>
string(20) "Concorde 2, Brighton"
["event_date"]=>
string(10) "2017-02-20"
["event_time"]=>
string(8) "20:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "50.817321799999990"
["geo_long"]=>
string(17) "-0.12304610000001"
["tags"]=>
string(30) "rock,alternative,indie"
}
[1]=>
array(9) {
["id"]=>
string(1) "4"
["title"]=>
string(9) "Blink-182"
["location"]=>
string(25) "Motorpoint Arena, Cardiff"
["event_date"]=>
string(10) "2017-07-03"
["event_time"]=>
string(8) "18:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.478937400000010"
["geo_long"]=>
string(17) "-3.17172289999996"
["tags"]=>
string(14) "rock,metal"
}
[2]=>
array(9) {
["id"]=>
string(1) "8"
["title"]=>
string(5) "Ghost"
["location"]=>
string(29) "O2 Forum Kentish Town, London"
["event_date"]=>
string(10) "2017-03-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.552197000000010"
["geo_long"]=>
string(17) "-0.14196900000002"
["tags"]=>
string(30) "rock,alternative,indie"
}
[3]=>
array(9) {
["id"]=>
string(2) "10"
["title"]=>
string(11) "Courteeners"
["location"]=>
string(39) "Emirates Old Trafford, Lancashire C.C.C"
["event_date"]=>
string(10) "2017-05-27"
["event_time"]=>
string(8) "16:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.456428000000000"
["geo_long"]=>
string(17) "-2.28679699999998"
["tags"]=>
string(30) "rock,alternative,indie"
}
}
["alternative"]=>
array(4) {
[0]=>
array(9) {
["id"]=>
string(1) "1"
["title"]=>
string(15) "Teleman Tickets"
["location"]=>
string(20) "Concorde 2, Brighton"
["event_date"]=>
string(10) "2017-02-20"
["event_time"]=>
string(8) "20:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "50.817321799999990"
["geo_long"]=>
string(17) "-0.12304610000001"
["tags"]=>
string(30) "rock,alternative,indie"
}
[1]=>
array(9) {
["id"]=>
string(1) "6"
["title"]=>
string(6) "Sum 41"
["location"]=>
string(23) "O2 Academy Leeds, Leeds"
["event_date"]=>
string(10) "2017-02-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.802188400000000"
["geo_long"]=>
string(17) "-1.54713770000001"
["tags"]=>
string(21) "alternative,indie"
}
[2]=>
array(9) {
["id"]=>
string(1) "8"
["title"]=>
string(5) "Ghost"
["location"]=>
string(29) "O2 Forum Kentish Town, London"
["event_date"]=>
string(10) "2017-03-26"
["event_time"]=>
string(8) "19:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "51.552197000000010"
["geo_long"]=>
string(17) "-0.14196900000002"
["tags"]=>
string(30) "rock,alternative,indie"
}
[3]=>
array(9) {
["id"]=>
string(2) "10"
["title"]=>
string(11) "Courteeners"
["location"]=>
string(39) "Emirates Old Trafford, Lancashire C.C.C"
["event_date"]=>
string(10) "2017-05-27"
["event_time"]=>
string(8) "16:00:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "53.456428000000000"
["geo_long"]=>
string(17) "-2.28679699999998"
["tags"]=>
string(30) "rock,alternative,indie"
}
}
["sax"]=>
array(1) {
[0]=>
array(9) {
["id"]=>
string(1) "3"
["title"]=>
string(9) "Take That"
["location"]=>
string(22) "The SSE Hydro, Glasgow"
["event_date"]=>
string(10) "2017-05-11"
["event_time"]=>
string(8) "18:30:00"
["url"]=>
string(1) "0"
["geo_lat"]=>
string(18) "55.860156000000000"
["geo_long"]=>
string(17) "-4.28525800000000"
["tags"]=>
string(24) "pop,boy-band,sax"
}
}
}
I'm going to assume that if two bands have the same 'id' then they are identical
$unique_bands = array();
// if the master array is called bands
foreach($bands as $genre){
foreach($genre as $band){
$unqiue_bands[$band['id']] = $band;
}
}
Maybe put $unique_bands = array_values(array_filter($unique_bands)); at the end to reindex the array
You have a solution on the official documentation... A person made a simple function to do exactly what you want.
Example array:
<?php
$details = array(
0 => array("id"=>"1", "name"=>"Mike", "num"=>"9876543210"),
1 => array("id"=>"2", "name"=>"Carissa", "num"=>"08548596258"),
2 => array("id"=>"1", "name"=>"Mathew", "num"=>"784581254"),
);
?>
Function:
<?php
function unique_multidim_array($array, $key) {
$temp_array = array();
$i = 0;
$key_array = array();
foreach($array as $val) {
if (!in_array($val[$key], $key_array)) {
$key_array[$i] = $val[$key];
$temp_array[$i] = $val;
}
$i++;
}
return $temp_array;
}
?>
You will have to fix it to work your for array dimension.

Php getting data out of an array

I have a massive array that i can't get data out of. I can only get data out of the first set of items.
I need to get to
["USFICO"]=>
array(3) {
["FICOScore"]=>
string(5) "00650"
out of it. But i can only get the top portion to work w/ $tester = $array['EfxReport']['#attributes']['reportId']; outputs to string(22) "USConsumerCreditReport" as expected.
how can i get the FICO score out of this array.
Here is the array.
array(1) {
["EfxReport"]=>
array(3) {
["#attributes"]=>
array(2) {
["requestNumber"]=>
string(1) "1"
["reportId"]=>
string(22) "USConsumerCreditReport"
}
["USDecisionPowerExpressReports"]=>
array(1) {
["USDecisionPowerExpressReport"]=>
array(4) {
["#attributes"]=>
array(2) {
["subjectType"]=>
string(7) "Subject"
["multipleNumber"]=>
string(1) "1"
}
["USMasterHeader"]=>
array(5) {
["CustomerReferenceNumber"]=>
string(6) "EFX QA"
["CustomerNumber"]=>
string(10) "999KI00553"
["ECOAInquiryType"]=>
string(1) "I"
["DateOfRequest"]=>
string(10) "02/23/2017"
["EquifaxReferenceNumber"]=>
string(9) "187391427"
}
["USConsumerCreditReport"]=>
array(6) {
["#attributes"]=>
array(2) {
["subjectType"]=>
string(7) "Subject"
["multipleNumber"]=>
string(1) "1"
}
["USHeader"]=>
array(3) {
["Request"]=>
array(6) {
["CustomerReferenceNumber"]=>
string(6) "EFX QA"
["CustomerNumber"]=>
string(10) "999KI00553"
["ConsumerReferralCode"]=>
string(3) "024"
["ECOAInquiryType"]=>
string(1) "I"
["NumberOfMonthsToCountInquiries"]=>
string(14) "Last 24 Months"
["NumberOfMonthsToCountDelinquencies"]=>
string(23) "Last 6 Years, 11 Months"
}
["CreditFile"]=>
array(11) {
["HitCode"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "1"
["description"]=>
string(3) "Hit"
}
}
["FileSinceDate"]=>
string(10) "04/16/2003"
["DateOfLastActivity"]=>
string(10) "01/24/2017"
["DateOfRequest"]=>
string(10) "02/23/2017"
["Identityscans"]=>
array(1) {
["Identityscan"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "8"
["description"]=>
string(74) "Unable to perform telephone validation due to insufficient telephone input"
}
}
}
["AddressDiscrepancyIndicator"]=>
string(1) "N"
["CreateCode"]=>
string(1) "2"
["FileStatus1"]=>
string(3) "016"
["FileStatus2"]=>
string(3) "242"
["FileStatus3"]=>
string(3) "004"
["BureauCode"]=>
string(3) "244"
}
["Subject"]=>
array(2) {
["SubjectName"]=>
array(3) {
["LastName"]=>
string(7) "DGNNLXZ"
["FirstName"]=>
string(7) "CHANITA"
["MiddleName"]=>
string(1) "S"
}
["SubjectId"]=>
array(2) {
["SubjectSSN"]=>
string(8) "66639074"
["DateOfBirth"]=>
string(10) "08/17/1988"
}
}
}
["USAddresses"]=>
array(1) {
["USAddress"]=>
array(3) {
[0]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "CA"
["description"]=>
string(15) "Current Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "4338"
["StreetName"]=>
string(9) "W POTOMAC"
["StreetType"]=>
string(3) "AVE"
}
["City"]=>
string(7) "CHICAGO"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "60651"
["DateAddressFirstReported"]=>
string(7) "07/2015"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "02/2017"
}
[1]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "FA"
["description"]=>
string(14) "Former Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "1301"
["StreetName"]=>
string(7) "BRUMMEL"
["StreetType"]=>
string(8) "ST APT 8"
}
["City"]=>
string(8) "EVANSTON"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "60202"
["DateAddressFirstReported"]=>
string(7) "04/2015"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "04/2015"
}
[2]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "F2"
["description"]=>
string(21) "Second Former Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "1208"
["StreetName"]=>
string(11) "W JEFFERSON"
["StreetType"]=>
string(8) "ST APT C"
}
["City"]=>
string(11) "SPRINGFIELD"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "62702"
["DateAddressFirstReported"]=>
string(7) "06/2014"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "06/2014"
}
}
}
["USEmployments"]=>
array(1) {
["USEmployment"]=>
array(3) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "ES"
["description"]=>
string(24) "Last Reported Employment"
}
["Occupation"]=>
string(14) "CORRECTION OFF"
["Employer"]=>
string(18) "MACON STATE PRISON"
}
}
["USFICO"]=>
array(3) {
["FICOScore"]=>
string(5) "00650"
["ScoreReasons"]=>
array(1) {
["ScoreReason"]=>
array(4) {
[0]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00038"
["description"]=>
string(69) "Serious delinquency, and derogatory public record or collection filed"
["number"]=>
string(1) "1"
}
}
[1]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00010"
["description"]=>
string(76) "Prop of balances to credit limits is too high on bank rev or other rev accts"
["number"]=>
string(1) "2"
}
}
[2]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00018"
["description"]=>
string(35) "Number of accounts with delinquency"
["number"]=>
string(1) "3"
}
}
[3]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00014"
["description"]=>
string(45) "Length of time accounts have been established"
["number"]=>
string(1) "4"
}
}
}
}
["ScoreIndicator"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "J"
["description"]=>
string(39) "FICO Score 5 based on Equifax Data (NF)"
}
}
}
["USIdentificationSSN"]=>
array(4) {
["MDBSubjectSSN"]=>
string(9) "666390749"
["InquirySubjectSSN"]=>
string(9) "666390749"
["InquirySSNDateIssued"]=>
string(4) "1992"
["InquirySSNStateIssued"]=>
string(2) "GA"
}
}
["USDecisionPowerExpressSegment"]=>
array(4) {
["ConsumerDisclosureIndicator"]=>
array(0) {
}
["ReportTextMessage"]=>
string(7) "OFFER C"
["SSNVarianceIndicator"]=>
array(0) {
}
["DPExpressProducts"]=>
array(1) {
["DPExpressProduct"]=>
array(4) {
[0]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "1"
}
["Description"]=>
string(1) "A"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[1]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "2"
}
["Description"]=>
string(1) "B"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[2]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "3"
}
["Description"]=>
string(1) "C"
["ApprovalIndicator"]=>
string(1) "Y"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[3]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "4"
}
["Description"]=>
string(1) "D"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
}
}
}
}
}
["USPrintImage"]=>
array(0) {
}
}
}
What's the error you're getting? Try:
$tester = $array['EfxReport']['USDecisionPowerExpressReports']['USDecisionPowerExpressReport']['USConsumerCreditReport']['USFICO']['FICOScore'];
Also I really hope this is fake data, you've included very personal/sensitive information in your array printout.

Create an array from another array result - php [duplicate]

This question already has answers here:
MYSQL SUM GROUP BY
(2 answers)
Closed 7 years ago.
I have 2 kind of classes: math and physics.
In the loop , count(lessonclasses) is equal to 2 then 3.
How can I proceed for my expected output ,
My code is :
$result[]=array();
foreach($lessons as $nameLesson)
{
$lessonclasses=$Board->GetLessonsClass($iduser,$nameLesson);
$tabPrice=$redevance->detailPriceForLesson($nameLesson)
$price=$tabPrice[0];
$frequency=$tabPrice[1];
//echo "nb of class per lesson: ".count($lessonclasses);
for($i=0;$i<count($lessonclasses);$i++)
{
//var_dump($lessonclasses);
$name=$lessonclasses[$i][0];
$amount=$lessonclasses[$i][1];
$timelessonstart=$lessonclasses[$i][2];
$timelessonend=$lessonclasses[$i][3];
$result[$i][]=array($name,$price."€/".$frequency,$timelessonstart,$timelessonend,$amount);
//$arrayOptions[$nbLessons][]=$options; //for keep values
//$nbLessons=$nbLessons+1;
}
}
var_dump($result);
I have an array like :
array(3) {
[0]=> array(2) {
[0]=> array(5) {
[0]=> string(15) "maths"
[1]=> string(11) "10.00"
[2]=> string(10) "2015-06-17"
[3]=> string(1) "-"
[4]=> string(6) "10.00"
}
[1]=> array(5) {
[0]=> string(31) "physique"
[1]=> string(10) "6.00"
[2]=> string(10) "2015-01-01"
[3]=> string(1) "-"
[4]=> string(5) "36.00"
}
}
[1]=> array(2) {
[0]=> array(5) {
[0]=> string(15) "maths"
[1]=> string(11) "20.00"
[2]=> string(10) "2015-06-17"
[3]=> string(1) "-"
[4]=> string(6) "100.0"
}
[1]=> array(5) {
[0]=> string(31) "physique"
[1]=> string(10) "16.00"
[2]=> string(10) "2015-05-01"
[3]=> string(1) "-"
[4]=> string(5) "36.00"
}
}
[2]=> array(1) {
[0]=> array(5) {
[0]=> string(15) "Maths" [1]=> string(11) "11.00" [2]=> string(10) "2015-05-17" [3]=> string(1) "-" [4]=> string(5) "20.00" } } }
My expected output is :
array(3) {
[0]=> array(2) {
[0]=> array(5) {
[0]=> string(15) "maths"
[1]=> string(11) "10.00"
[2]=> string(10) "2015-06-17"
[3]=> string(1) "-"
[4]=> string(6) "10.00"
}
[1]=> array(2) {
[0]=> array(5) {
[0]=> string(15) "maths"
[1]=> string(11) "20.00"
[2]=> string(10) "2015-06-17"
[3]=> string(1) "-"
[4]=> string(6) "100.0"
}
[2]=> array(5) {
[0]=> string(31) "math"
[1]=> string(10) "11.00"
[2]=> string(10) "2015-05-01"
[3]=> string(1) "-"
[4]=> string(5) "36.00"
}
}
[1]=> array(2) {
[0]=> array(5) {
[0]=> string(31) "physique"
[1]=> string(10) "6.00"
[2]=> string(10) "2015-01-01"
[3]=> string(1) "-"
[4]=> string(5) "36.00"
}
[1]=> array(5) {
[0]=> string(31) "physique"
[1]=> string(10) "16.00"
[2]=> string(10) "2015-05-01"
[3]=> string(1) "-"
[4]=> string(5) "36.00"
}
}
} }
SELECT name,sum(qty) FROM tableName group by name;
Simply
SELECT name, SUM(qty) AS total_amount FROM table GROUP BY name
you need to use sum
SELECT name,sum(qty) FROM table_name group by name;
Its working for you..
SELECT name,sum(qty) FROM table_name GROUP BY name;

I don't know how to "sort" arrays

I have this array :
array(2) {
[1]=>
array(4) {
["name"]=>
string(14) "Les Contenants"
["ordre"]=>
string(1) "3"
[9]=>
array(1) {
["name"]=>
string(20) "Corbeilles unitaires"
}
[10]=>
array(1) {
["name"]=>
string(6) "Mannes"
}
}
[6]=>
array(3) {
["name"]=>
string(7) "L'utile"
["ordre"]=>
string(1) "1"
[133]=>
array(3) {
["name"]=>
string(7) "Paniers"
[192]=>
array(1) {
["name"]=>
string(13) "à provisions"
}
[193]=>
array(2) {
["name"]=>
string(13) "anses mobiles"
[201]=>
array(1) {
["name"]=>
string(19) "non doublés tissus"
}
}
}
}
}
I need to sort this array on this key : array[$i]['ordre'] on an ascending order.
The results must be :
array(2) {
[6]=>
array(3) {
["name"]=>
string(7) "L'utile"
["ordre"]=>
string(1) "1"
[133]=>
array(3) {
["name"]=>
string(7) "Paniers"
[192]=>
array(1) {
["name"]=>
string(13) "à provisions"
}
[193]=>
array(2) {
["name"]=>
string(13) "anses mobiles"
[201]=>
array(1) {
["name"]=>
string(19) "non doublés tissus"
}
}
}
}
[1]=>
array(4) {
["name"]=>
string(14) "Les Contenants"
["ordre"]=>
string(1) "3"
[9]=>
array(1) {
["name"]=>
string(20) "Corbeilles unitaires"
}
[10]=>
array(1) {
["name"]=>
string(6) "Mannes"
}
}
}
Have you an idea to do it ?
usort($array,function($a,$b) {return $a['ordre']-$b['ordre'];});
Or, if your version of PHP doesn't support lambda-functions:
usort($array,create_function('$a,$b','return $a["ordre"]-$b["ordre"];'));

Categories