Array with 91 items, trying to reduce redundancy - php

I have an array with 91 items, and I don't want to constantly use $data[1], $data[2], etc. and it seems redundant to make 91 separate variables just to make it easier to remember what each data item does.
Does anyone know how I can give each of these items a name easier? Or am I just stuck with manually naming each one...
array(91) { [0]=> string(6) "537146" [1]=> string(4) "1212" [2]=> string(7) "7902400" [3]=> string(6) "670563" [4]=> string(2) "69" [5]=> string(6) "674789" [6]=> string(6) "576650" [7]=> string(2) "68" [8]=> string(6) "628147" [9]=> string(6) "690316" [10]=> string(2) "71" [11]=> string(6) "831597" [12]=> string(6) "746547" [13]=> string(2) "70" [14]=> string(6) "776478" [15]=> string(6) "832324" [16]=> string(2) "65" [17]=> string(6) "455705" [18]=> string(6) "710640" [19]=> string(2) "47" [20]=> string(5) "76682" [21]=> string(6) "722402" [22]=> string(2) "66" [23]=> string(6) "512396" [24]=> string(6) "863938" [25]=> string(2) "51" [26]=> string(6) "123086" [27]=> string(6) "143396" [28]=> string(2) "80" [29]=> string(7) "2163323" [30]=> string(6) "435239" [31]=> string(2) "67" [32]=> string(6) "560102" [33]=> string(7) "1078055" [34]=> string(2) "47" [35]=> string(5) "80051" [36]=> string(6) "601043" [37]=> string(2) "51" [38]=> string(6) "114870" [39]=> string(6) "715865" [40]=> string(2) "51" [41]=> string(6) "112269" [42]=> string(6) "403800" [43]=> string(2) "57" [44]=> string(6) "219098" [45]=> string(6) "697401" [46]=> string(2) "52" [47]=> string(6) "124179" [48]=> string(6) "599311" [49]=> string(2) "38" [50]=> string(5) "32070" [51]=> string(6) "769359" [52]=> string(2) "44" [53]=> string(5) "59335" [54]=> string(6) "472791" [55]=> string(2) "53" [56]=> string(6) "138904" [57]=> string(6) "591165" [58]=> string(2) "55" [59]=> string(6) "172795" [60]=> string(6) "500981" [61]=> string(2) "33" [62]=> string(5) "19433" [63]=> string(6) "650383" [64]=> string(2) "23" [65]=> string(4) "6979" [66]=> string(6) "552008" [67]=> string(2) "29" [68]=> string(5) "12185" [69]=> string(6) "692439" [70]=> string(2) "25" [71]=> string(4) "7927" [72]=> string(2) "-1" [73]=> string(2) "-1" [74]=> string(2) "-1" [75]=> string(2) "-1" [76]=> string(6) "483773" [77]=> string(1) "6" [78]=> string(6) "362146" [79]=> string(1) "3" [80]=> string(6) "347664" [81]=> string(1) "3" [82]=> string(2) "-1" [83]=> string(2) "-1" [84]=> string(2) "-1" [85]=> string(2) "-1" [86]=> string(2) "-1" [87]=> string(2) "-1" [88]=> string(2) "-1" [89]=> string(2) "-1" [90]=> string(0) "" }

You can make a try like this way to create multiple variables for your each and every element of array using foreach().
foreach($array as $key=>$value){
${"var_$key"} = $value;
}
echo "variable no 1 is = $var_1, variable no 50 is = $var_50, and variable no 90 is = $var_90";
DEMO: https://3v4l.org/DXvVp

Related

oci_fetch_all equivalent for pdo?

I'm trying to get result from a postgres database with the fetchAll() function. But I have to get the same result from an Oracle DB and it doesn't work with the fetchAll() function.
With fetchall() i have an array with index numbers and each array represent a row from the db, but with oci_fetch_all each array have an array with the column name as index, and each array represent a column from the db and that's what I need
Postgres :
$stmt = $db->prepare($req);
$stmt->execute();
$res = $stmt->fetchAll();
output :
array(4) {
[0]=>
array(14) {
["PLU_PRESCRIPTION_S"]=>
string(18) "PLU_PRESCRIPTION_S"
[0]=>
string(18) "PLU_PRESCRIPTION_S"
["Critère"]=>
string(6) "02_PPA"
[1]=>
string(6) "02_PPA"
["type_prescription"]=>
string(6) "risque"
[2]=>
string(6) "risque"
["Aire parcelle (m²)"]=>
string(6) "298.62"
[3]=>
string(6) "298.62"
["Aire de lintersection (m²)"]=>
string(6) "298.62"
[4]=>
string(6) "298.62"
["%"]=>
string(6) "100.00"
[5]=>
string(6) "100.00"
["trig_comm"]=>
NULL
[6]=>
NULL
}
[1]=>
array(14) {
["PLU_PRESCRIPTION_S"]=>
string(18) "PLU_PRESCRIPTION_S"
[0]=>
string(18) "PLU_PRESCRIPTION_S"
["Critère"]=>
string(8) "04_zone1"
[1]=>
string(8) "04_zone1"
["type_prescription"]=>
string(3) "PDU"
[2]=>
string(3) "PDU"
["Aire parcelle (m²)"]=>
string(6) "298.62"
[3]=>
string(6) "298.62"
["Aire de lintersection (m²)"]=>
string(6) "298.62"
[4]=>
string(6) "298.62"
["%"]=>
string(6) "100.00"
[5]=>
string(6) "100.00"
["trig_comm"]=>
NULL
[6]=>
NULL
}
[2]=>
array(14) {
["PLU_PRESCRIPTION_S"]=>
string(18) "PLU_PRESCRIPTION_S"
[0]=>
string(18) "PLU_PRESCRIPTION_S"
["Critère"]=>
string(5) "07_MH"
[1]=>
string(5) "07_MH"
["type_prescription"]=>
string(10) "patrimoine"
[2]=>
string(10) "patrimoine"
["Aire parcelle (m²)"]=>
string(6) "298.62"
[3]=>
string(6) "298.62"
["Aire de lintersection (m²)"]=>
string(6) "298.62"
[4]=>
string(6) "298.62"
["%"]=>
string(6) "100.00"
[5]=>
string(6) "100.00"
["trig_comm"]=>
NULL
[6]=>
NULL
}
[3]=>
array(14) {
["PLU_PRESCRIPTION_S"]=>
string(18) "PLU_PRESCRIPTION_S"
[0]=>
string(18) "PLU_PRESCRIPTION_S"
["Critère"]=>
string(20) "18_OAP_communautaire"
[1]=>
string(20) "18_OAP_communautaire"
["type_prescription"]=>
string(3) "OAP"
[2]=>
string(3) "OAP"
["Aire parcelle (m²)"]=>
string(6) "298.62"
[3]=>
string(6) "298.62"
["Aire de lintersection (m²)"]=>
string(6) "298.62"
[4]=>
string(6) "298.62"
["%"]=>
string(6) "100.00"
[5]=>
string(6) "100.00"
["trig_comm"]=>
string(3) "CEN"
[6]=>
string(3) "CEN"
}
}
ORACLE :
if (oci_execute($ora_req)) {
// récupération des infos dans la base de donnée
$nrows = oci_fetch_all($ora_req, $res);
// Stockage des infos dans le tableau
array_push($arrPrescriptionS, $res);
}
OUTPUT :
array(0) { }
array(7) {
["'PLU_PRESCRIPTION_S'"]=>
array(4) {
[0]=>
string(18) "PLU_PRESCRIPTION_S"
[1]=>
string(18) "PLU_PRESCRIPTION_S"
[2]=>
string(18) "PLU_PRESCRIPTION_S"
[3]=>
string(18) "PLU_PRESCRIPTION_S"
}
["Critère"]=>
array(4) {
[0]=>
string(6) "02_PPA"
[1]=>
string(8) "04_zone1"
[2]=>
string(5) "07_MH"
[3]=>
string(20) "18_OAP_communautaire"
}
["TYPE_PRESCRIPTION"]=>
array(4) {
[0]=>
string(2) "02"
[1]=>
string(2) "04"
[2]=>
string(2) "07"
[3]=>
string(2) "18"
}
["Aire parcelle (m²)"]=>
array(4) {
[0]=>
string(6) "298,62"
[1]=>
string(6) "298,62"
[2]=>
string(6) "298,62"
[3]=>
string(6) "298,62"
}
["Aire de l'intersection (m²)"]=>
array(4) {
[0]=>
string(6) "298,62"
[1]=>
string(6) "298,62"
[2]=>
string(6) "298,62"
[3]=>
string(6) "298,62"
}
["%"]=>
array(4) {
[0]=>
string(3) "100"
[1]=>
string(3) "100"
[2]=>
string(3) "100"
[3]=>
string(3) "100"
}
["TRIG_COMM"]=>
array(4) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
[3]=>
string(3) "CEN"
}
}
thank's
This is not possible in PDO. PDO doesn't return results indexed by column names. This behaviour is not very intuitive when writing code, so it's best avoided. Use the normal fetch modes, which order results by rows.
If you need to write some shim for backwards compatibility you can do it yourself with nested loops.
$s = $pdo->query("SELECT * FROM bar");
$allByColumns = [];
foreach ($s->fetchAll(PDO::FETCH_ASSOC) as $index => $row) {
foreach ($row as $column => $value) {
$allByColumns[$column][$index] = $value;
}
}
var_dump($allByColumns);

double loop to extract information from an array

I have an array that is quite large. I need to extract the information from the "citis" and "avatarScores".The information of avatarscores is related to the information of citis.
For example city 1 belongs to player 1 who has the points that appear in avatarscores.
The citis array is always 17 places, but there does not have to be 17 cities.
The array of avatarscores is the size that cities actually exist.
The question is how can I do a double foreach, to extract the information from both arrays, and that they associate well so that the information of each city is correct.
I was doing a lot of testing, but duplicate records were continually coming out.There are only 10 cities in that array, and I always got about 100 cities (duplicate information)
The array
array(6) {
[0]=>
array(2) {
[0]=>
string(20) "updateBackgroundData"
[1]=>
object(stdClass)#2 (37) {
["id"]=>
string(2) "74"
["type"]=>
int(5)
["name"]=>
string(8) "Shaymios"
["xCoord"]=>
string(2) "44"
["yCoord"]=>
string(2) "47"
["tradegood"]=>
string(1) "3"
["tradegoodTarget"]=>
string(8) "noluxury"
["resourceLevel"]=>
string(2) "26"
["tradegoodLevel"]=>
string(2) "21"
["wonder"]=>
string(1) "2"
["wonderLevel"]=>
string(1) "4"
["wonderName"]=>
string(22) "Gruta Sagrada de Hades"
["showResourceWorkers"]=>
int(0)
["showTradegoodWorkers"]=>
int(0)
["showAgora"]=>
int(1)
["canEnterResource"]=>
int(1)
["canEnterTradegood"]=>
int(1)
["tradegoodEndUpgradeTime"]=>
int(0)
["resourceEndUpgradeTime"]=>
int(0)
["wonderEndUpgradeTime"]=>
int(0)
["isOwnCityOnIsland"]=>
bool(true)
["cities"]=>
array(17) {
[0]=>
object(stdClass)#3 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[1]=>
object(stdClass)#4 (13) {
["type"]=>
string(4) "city"
["name"]=>
string(7) "Nothing"
["id"]=>
int(64501)
["level"]=>
string(2) "10"
["ownerId"]=>
string(5) "27450"
["ownerName"]=>
string(7) "Paisano"
["ownerAllyId"]=>
string(3) "321"
["ownerAllyTag"]=>
string(5) "CROMA"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[2]=>
object(stdClass)#5 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[3]=>
object(stdClass)#6 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[4]=>
object(stdClass)#7 (12) {
["type"]=>
string(4) "city"
["name"]=>
string(5) "Polis"
["id"]=>
int(64437)
["level"]=>
string(1) "1"
["ownerId"]=>
string(5) "28312"
["ownerName"]=>
string(14) "Agamemnon-3798"
["ownerAllyId"]=>
string(1) "0"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(2)
["infestedByPlague"]=>
bool(false)
}
[5]=>
object(stdClass)#8 (13) {
["type"]=>
string(4) "city"
["name"]=>
string(9) "Evaroschi"
["id"]=>
int(5405)
["level"]=>
string(2) "26"
["ownerId"]=>
string(4) "3739"
["ownerName"]=>
string(6) "cesar2"
["ownerAllyId"]=>
string(3) "324"
["ownerAllyTag"]=>
string(4) "-T1-"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[6]=>
object(stdClass)#9 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[7]=>
object(stdClass)#10 (13) {
["type"]=>
string(4) "city"
["name"]=>
string(9) "Cristal I"
["id"]=>
int(849)
["level"]=>
string(2) "27"
["ownerId"]=>
string(3) "849"
["ownerName"]=>
string(7) "DaniloJ"
["ownerAllyId"]=>
string(1) "2"
["ownerAllyTag"]=>
string(4) "-ZT-"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[8]=>
object(stdClass)#11 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[9]=>
object(stdClass)#12 (12) {
["type"]=>
string(4) "city"
["name"]=>
string(5) "Polis"
["id"]=>
int(64892)
["level"]=>
string(1) "1"
["ownerId"]=>
string(5) "28488"
["ownerName"]=>
string(8) "-NAGATO-"
["ownerAllyId"]=>
string(1) "0"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(8) "inactive"
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[10]=>
object(stdClass)#13 (13) {
["type"]=>
string(4) "city"
["name"]=>
string(4) "0001"
["id"]=>
int(40246)
["level"]=>
string(2) "20"
["ownerId"]=>
string(5) "18230"
["ownerName"]=>
string(13) "NeWRomerOrdeR"
["ownerAllyId"]=>
string(3) "307"
["ownerAllyTag"]=>
string(4) "ROMA"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[11]=>
object(stdClass)#14 (12) {
["type"]=>
string(4) "city"
["name"]=>
string(5) "Polis"
["id"]=>
int(64942)
["level"]=>
string(1) "1"
["ownerId"]=>
string(5) "28503"
["ownerName"]=>
string(13) "AnitaFacilita"
["ownerAllyId"]=>
string(1) "0"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(8) "inactive"
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[12]=>
object(stdClass)#15 (12) {
["type"]=>
string(4) "city"
["name"]=>
string(5) "Polis"
["id"]=>
int(64988)
["level"]=>
string(1) "1"
["ownerId"]=>
string(5) "28523"
["ownerName"]=>
string(9) "Sklavidel"
["ownerAllyId"]=>
string(1) "0"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(4) "noob"
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[13]=>
object(stdClass)#16 (12) {
["type"]=>
string(4) "city"
["name"]=>
string(5) "Polis"
["id"]=>
int(63482)
["level"]=>
string(2) "14"
["ownerId"]=>
string(5) "27754"
["ownerName"]=>
string(10) "OL-Fredy97"
["ownerAllyId"]=>
string(1) "0"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[14]=>
object(stdClass)#17 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(6) "normal"
}
[15]=>
object(stdClass)#18 (13) {
["type"]=>
string(4) "city"
["name"]=>
string(6) "Atenas"
["id"]=>
int(32646)
["level"]=>
string(2) "24"
["ownerId"]=>
string(5) "14700"
["ownerName"]=>
string(7) "Charles"
["ownerAllyId"]=>
string(3) "307"
["ownerAllyTag"]=>
string(4) "ROMA"
["hasTreaties"]=>
int(0)
["actions"]=>
array(0) {
}
["state"]=>
string(0) ""
["viewAble"]=>
int(0)
["infestedByPlague"]=>
bool(false)
}
[16]=>
object(stdClass)#19 (6) {
["id"]=>
int(-1)
["type"]=>
string(10) "buildplace"
["name"]=>
string(7) "Terreno"
["level"]=>
int(0)
["viewAble"]=>
int(1)
["buildplace_type"]=>
string(7) "premium"
}
}
["barbarians"]=>
object(stdClass)#20 (11) {
["invisible"]=>
int(0)
["actionTitle"]=>
string(55) "¡Ninguna tropa/barco mercante disponible para saquear!"
["actionClass"]=>
string(19) "plundering disabled"
["actionLink"]=>
string(0) ""
["count"]=>
int(1)
["wallLevel"]=>
int(0)
["level"]=>
int(1)
["underAttack"]=>
int(0)
["isTradegoodSiege"]=>
int(0)
["city"]=>
string(8) "kingOlaf"
["destroyed"]=>
int(0)
}
["avatarScores"]=>
object(stdClass)#22 (10) {
["849"]=>
object(stdClass)#21 (6) {
["avatar_id"]=>
string(3) "849"
["place"]=>
string(1) "7"
["building_score_main"]=>
string(11) "379,322,313"
["research_score_main"]=>
string(10) "72,145,880"
["army_score_main"]=>
string(7) "250,190"
["trader_score_secondary"]=>
string(10) "12,848,160"
}
["3739"]=>
object(stdClass)#23 (6) {
["avatar_id"]=>
string(5) "3,739"
["place"]=>
string(3) "165"
["building_score_main"]=>
string(10) "60,479,333"
["research_score_main"]=>
string(9) "7,276,760"
["army_score_main"]=>
string(7) "199,960"
["trader_score_secondary"]=>
string(9) "4,120,270"
}
["14700"]=>
object(stdClass)#24 (6) {
["avatar_id"]=>
string(6) "14,700"
["place"]=>
string(3) "237"
["building_score_main"]=>
string(10) "24,048,522"
["research_score_main"]=>
string(9) "7,276,760"
["army_score_main"]=>
string(7) "380,000"
["trader_score_secondary"]=>
string(9) "7,027,608"
}
["18230"]=>
object(stdClass)#25 (6) {
["avatar_id"]=>
string(6) "18,230"
["place"]=>
string(3) "243"
["building_score_main"]=>
string(10) "26,427,220"
["research_score_main"]=>
string(9) "3,953,400"
["army_score_main"]=>
string(7) "472,620"
["trader_score_secondary"]=>
string(9) "2,657,737"
}
["27450"]=>
object(stdClass)#26 (6) {
["avatar_id"]=>
string(6) "27,450"
["place"]=>
string(3) "334"
["building_score_main"]=>
string(9) "6,161,438"
["research_score_main"]=>
string(7) "891,972"
["army_score_main"]=>
string(7) "144,860"
["trader_score_secondary"]=>
string(6) "41,764"
}
["27754"]=>
object(stdClass)#27 (6) {
["avatar_id"]=>
string(6) "27,754"
["place"]=>
string(3) "349"
["building_score_main"]=>
string(9) "4,536,533"
["research_score_main"]=>
string(7) "702,972"
["army_score_main"]=>
string(6) "20,660"
["trader_score_secondary"]=>
string(7) "125,021"
}
["28312"]=>
object(stdClass)#28 (6) {
["avatar_id"]=>
string(6) "28,312"
["place"]=>
string(3) "551"
["building_score_main"]=>
string(1) "0"
["research_score_main"]=>
string(1) "0"
["army_score_main"]=>
string(1) "0"
["trader_score_secondary"]=>
string(6) "61,843"
}
["28488"]=>
object(stdClass)#29 (6) {
["avatar_id"]=>
string(6) "28,488"
["place"]=>
string(3) "552"
["building_score_main"]=>
string(1) "0"
["research_score_main"]=>
string(1) "0"
["army_score_main"]=>
string(1) "0"
["trader_score_secondary"]=>
string(6) "18,439"
}
["28503"]=>
object(stdClass)#30 (6) {
["avatar_id"]=>
string(6) "28,503"
["place"]=>
string(3) "555"
["building_score_main"]=>
string(1) "0"
["research_score_main"]=>
string(1) "0"
["army_score_main"]=>
string(1) "0"
["trader_score_secondary"]=>
string(6) "14,262"
}
["28523"]=>
object(stdClass)#31 (6) {
["avatar_id"]=>
string(6) "28,523"
["place"]=>
string(3) "498"
["building_score_main"]=>
string(1) "0"
["research_score_main"]=>
string(1) "0"
["army_score_main"]=>
string(3) "360"
["trader_score_secondary"]=>
string(6) "10,879"
}
}
["specialServerBadges"]=>
array(0) {
}
["selectedCityParameters"]=>
array(0) {
}
["island"]=>
string(2) "74"
["isHeliosTowerBuilt"]=>
bool(false)
["heliosTop"]=>
int(1)
["heliosMid"]=>
int(1)
["heliosBase"]=>
int(1)
["heliosName"]=>
string(15) "Ruinas de torre"
["heliosTooltip"]=>
string(24) "Torre de Helios inactiva"
["heliosActive"]=>
int(0)
["showResourceBonusIcon"]=>
int(0)
["showTradegoodBonusIcon"]=>
int(0)
["walkers"]=>
object(stdClass)#32 (1) {
["add"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
[0]=>
string(18) "updateTemplateData"
[1]=>
string(0) ""
}
[2]=>
array(2) {
[0]=>
string(9) "popupData"
[1]=>
NULL
}
[3]=>
array(2) {
[0]=>
string(17) "ingameCounterData"
[1]=>
NULL
}
[4]=>
array(2) {
[0]=>
string(23) "removeIngameCounterData"
[1]=>
NULL
}
[5]=>
array(2) {
[0]=>
string(14) "updateBacklink"
[1]=>
NULL
}
}
code to extract
$owners = [];
foreach($final[0][1]->cities as $city){
$owner = "";
$allyTag = "";
$namecity = "";
$citylevel ="";
$idowner = "";
if(isset($city->ownerName)){
$owner = $city->ownerName;
if(isset($city->ownerId)){
$idowner = $city->ownerId;
if (isset($city->name)) {
$namecity = $city->name;
if (isset($city->level)) {
$citylevel = $city->level;
if(isset($city->ownerAllyTag)){
$allyTag = $city->ownerAllyTag;
}
array_push($owners, ["idowner"=>$idowner, "citylevel"=>$citylevel, "owner"=>$owner, "allyTag" => $allyTag, "namecity" => $namecity]);
}}}}
}
code from avatarscores that has to be unified with the one above
$vavatar_id = "";
$vplace = "";
$vbuilding_score_main = "";
$vresearch_score_main = "";
$varmy_score_main = "";
$vtrader_score_secondary = "";
if(isset($scores->avatar_id)){
$vavatar_id = $scores->avatar_id;
}
if(isset($scores->place)){
$vplace = $scores->place;
}
if(isset($scores->building_score_main)){
$vbuilding_score_main = $scores->building_score_main;
}
if(isset($scores->research_score_main)){
$vresearch_score_main = $scores->research_score_main;
}
if(isset($scores->army_score_main)){
$varmy_score_main = $scores->army_score_main;
}
if(isset($scores->trader_score_secondary)){
$vtrader_score_secondary = $scores->trader_score_secondary;
}
array_push($final, ["avatar_id"=>$vavatar_id,"place"=>$vplace,"building_score_main"=>$vbuilding_score_main,"research_score_main"=>$vresearch_score_main,"army_score_main"=>$varmy_score_main,"trader_score_secondary"=>$vtrader_score_secondary ]);
}
Loop through the avatarScores array, then search for the key in the idowner field of the $owners array.
foreach (foreach($final[0][1]->avatarScores as $avatarOwner => $scores) {
$vavatar_id = "";
$vplace = "";
$vbuilding_score_main = "";
$vresearch_score_main = "";
$varmy_score_main = "";
$vtrader_score_secondary = "";
$city = null;
foreach ($owners as $owner) {
if ($owner['idowner'] == $avatarOwner) {
$city = $owner;
break;
}
}
if(isset($scores->avatar_id)){
$vavatar_id = $scores->avatar_id;
}
if(isset($scores->place)){
$vplace = $scores->place;
}
if(isset($scores->building_score_main)){
$vbuilding_score_main = $scores->building_score_main;
}
if(isset($scores->research_score_main)){
$vresearch_score_main = $scores->research_score_main;
}
if(isset($scores->army_score_main)){
$varmy_score_main = $scores->army_score_main;
}
if(isset($scores->trader_score_secondary)){
$vtrader_score_secondary = $scores->trader_score_secondary;
}
}

'ImagickException', 'NoDecodeDelegateForThisImageFormat `TMP' # error/constitute.c/ReadImage/501'

I try to install magick, and works, but when i need to work with PDF file i have error.
I use xampp
php 5.6
Compiler MSVC11 (Visual C++ 2012)
Architecture x86
Thread Safety enabled
64bit system
windows Server 2012 R2
Bin/Dlls:
php_imagick-3.1.2-5.6-ts-vc11-x86
ImageMagick-6.9.3-7-vc11-x86
I try to install ghostpcl-9.27-win32.
version:
ImageMagick 7.0.8-48 Q16 x86 2019-06-01
$im = new Imagick();
$im->setResolution(300,300);
$im->readimage($pdf->tmp_name);
$im->setImageFormat('jpeg');
$im->cropImage(500, 500, 50, 1420);
$im->writeImage($pdf->tmp_name . '.jpg');
$im->clear();
$im->destroy();
Fatal error: Uncaught exception 'ImagickException' with message 'NoDecodeDelegateForThisImageFormat `TMP' # error/constitute.c/ReadImage/501' in C:\xampp\htdocs\adm_engemed_ts5\eol\scr\savePDF.php:60 Stack trace: #0 C:\xampp\htdocs\adm_engemed_ts5\eol\scr\savePDF.php(60): Imagick->readimage('C:\xampp\tmp\ph...') #1 {main} thrown in C:\xampp\htdocs\adm_engemed_ts5\eol\scr\savePDF.php on line 60
$im->queryFormats();
When i use:
array(234) {
[0]=>
string(3) "3FR"
[1]=>
string(3) "AAI"
[2]=>
string(2) "AI"
[3]=>
string(3) "ART"
[4]=>
string(3) "ARW"
[5]=>
string(3) "AVI"
[6]=>
string(3) "AVS"
[7]=>
string(3) "BGR"
[8]=>
string(4) "BGRA"
[9]=>
string(4) "BGRO"
[10]=>
string(3) "BIE"
[11]=>
string(3) "BMP"
[12]=>
string(4) "BMP2"
[13]=>
string(4) "BMP3"
[14]=>
string(3) "BRF"
[15]=>
string(3) "CAL"
[16]=>
string(4) "CALS"
[17]=>
string(6) "CANVAS"
[18]=>
string(7) "CAPTION"
[19]=>
string(3) "CIN"
[20]=>
string(3) "CIP"
[21]=>
string(4) "CLIP"
[22]=>
string(9) "CLIPBOARD"
[23]=>
string(4) "CMYK"
[24]=>
string(5) "CMYKA"
[25]=>
string(3) "CR2"
[26]=>
string(3) "CRW"
[27]=>
string(3) "CUR"
[28]=>
string(3) "CUT"
[29]=>
string(4) "DATA"
[30]=>
string(3) "DCM"
[31]=>
string(3) "DCR"
[32]=>
string(3) "DCX"
[33]=>
string(3) "DDS"
[34]=>
string(5) "DFONT"
[35]=>
string(4) "DJVU"
[36]=>
string(3) "DNG"
[37]=>
string(3) "DOT"
[38]=>
string(3) "DPS"
[39]=>
string(3) "DPX"
[40]=>
string(4) "DXT1"
[41]=>
string(4) "DXT5"
[42]=>
string(3) "EMF"
[43]=>
string(4) "EPDF"
[44]=>
string(3) "EPI"
[45]=>
string(3) "EPS"
[46]=>
string(4) "EPS2"
[47]=>
string(4) "EPS3"
[48]=>
string(4) "EPSF"
[49]=>
string(4) "EPSI"
[50]=>
string(3) "EPT"
[51]=>
string(4) "EPT2"
[52]=>
string(4) "EPT3"
[53]=>
string(3) "ERF"
[54]=>
string(3) "EXR"
[55]=>
string(3) "FAX"
[56]=>
string(4) "FITS"
[57]=>
string(3) "FPX"
[58]=>
string(7) "FRACTAL"
[59]=>
string(3) "FTS"
[60]=>
string(2) "G3"
[61]=>
string(3) "GIF"
[62]=>
string(5) "GIF87"
[63]=>
string(8) "GRADIENT"
[64]=>
string(4) "GRAY"
[65]=>
string(6) "GROUP4"
[66]=>
string(2) "GV"
[67]=>
string(1) "H"
[68]=>
string(4) "HALD"
[69]=>
string(3) "HDR"
[70]=>
string(9) "HISTOGRAM"
[71]=>
string(3) "HRZ"
[72]=>
string(3) "HTM"
[73]=>
string(4) "HTML"
[74]=>
string(3) "ICB"
[75]=>
string(3) "ICO"
[76]=>
string(4) "ICON"
[77]=>
string(3) "IIQ"
[78]=>
string(4) "INFO"
[79]=>
string(6) "INLINE"
[80]=>
string(3) "IPL"
[81]=>
string(6) "ISOBRL"
[82]=>
string(7) "ISOBRL6"
[83]=>
string(3) "J2C"
[84]=>
string(3) "J2K"
[85]=>
string(3) "JBG"
[86]=>
string(4) "JBIG"
[87]=>
string(3) "JNG"
[88]=>
string(3) "JNX"
[89]=>
string(3) "JP2"
[90]=>
string(3) "JPC"
[91]=>
string(3) "JPE"
[92]=>
string(4) "JPEG"
[93]=>
string(3) "JPG"
[94]=>
string(3) "JPM"
[95]=>
string(3) "JPS"
[96]=>
string(3) "JPT"
[97]=>
string(4) "JSON"
[98]=>
string(3) "K25"
[99]=>
string(3) "KDC"
[100]=>
string(5) "LABEL"
[101]=>
string(3) "M2V"
[102]=>
string(3) "M4V"
[103]=>
string(3) "MAC"
[104]=>
string(6) "MAGICK"
[105]=>
string(3) "MAP"
[106]=>
string(4) "MASK"
[107]=>
string(3) "MAT"
[108]=>
string(5) "MATTE"
[109]=>
string(3) "MEF"
[110]=>
string(4) "MIFF"
[111]=>
string(3) "MKV"
[112]=>
string(3) "MNG"
[113]=>
string(4) "MONO"
[114]=>
string(3) "MOV"
[115]=>
string(3) "MP4"
[116]=>
string(3) "MPC"
[117]=>
string(4) "MPEG"
[118]=>
string(3) "MPG"
[119]=>
string(3) "MRW"
[120]=>
string(3) "MSL"
[121]=>
string(4) "MSVG"
[122]=>
string(3) "MTV"
[123]=>
string(3) "MVG"
[124]=>
string(3) "NEF"
[125]=>
string(3) "NRW"
[126]=>
string(4) "NULL"
[127]=>
string(3) "ORF"
[128]=>
string(3) "OTB"
[129]=>
string(3) "OTF"
[130]=>
string(3) "PAL"
[131]=>
string(4) "PALM"
[132]=>
string(3) "PAM"
[133]=>
string(5) "PANGO"
[134]=>
string(7) "PATTERN"
[135]=>
string(3) "PBM"
[136]=>
string(3) "PCD"
[137]=>
string(4) "PCDS"
[138]=>
string(3) "PCL"
[139]=>
string(3) "PCT"
[140]=>
string(3) "PCX"
[141]=>
string(3) "PDB"
[142]=>
string(3) "PDF"
[143]=>
string(4) "PDFA"
[144]=>
string(3) "PEF"
[145]=>
string(3) "PES"
[146]=>
string(3) "PFA"
[147]=>
string(3) "PFB"
[148]=>
string(3) "PFM"
[149]=>
string(3) "PGM"
[150]=>
string(5) "PICON"
[151]=>
string(4) "PICT"
[152]=>
string(3) "PIX"
[153]=>
string(5) "PJPEG"
[154]=>
string(6) "PLASMA"
[155]=>
string(3) "PNG"
[156]=>
string(5) "PNG00"
[157]=>
string(5) "PNG24"
[158]=>
string(5) "PNG32"
[159]=>
string(5) "PNG48"
[160]=>
string(5) "PNG64"
[161]=>
string(4) "PNG8"
[162]=>
string(3) "PNM"
[163]=>
string(3) "PPM"
[164]=>
string(7) "PREVIEW"
[165]=>
string(2) "PS"
[166]=>
string(3) "PS2"
[167]=>
string(3) "PS3"
[168]=>
string(3) "PSB"
[169]=>
string(3) "PSD"
[170]=>
string(4) "PTIF"
[171]=>
string(3) "PWP"
[172]=>
string(15) "RADIAL-GRADIENT"
[173]=>
string(3) "RAF"
[174]=>
string(3) "RAS"
[175]=>
string(3) "RAW"
[176]=>
string(3) "RGB"
[177]=>
string(4) "RGBA"
[178]=>
string(4) "RGBO"
[179]=>
string(3) "RGF"
[180]=>
string(3) "RLA"
[181]=>
string(3) "RLE"
[182]=>
string(3) "RMF"
[183]=>
string(3) "RW2"
[184]=>
string(3) "SCR"
[185]=>
string(10) "SCREENSHOT"
[186]=>
string(3) "SCT"
[187]=>
string(3) "SFW"
[188]=>
string(3) "SGI"
[189]=>
string(5) "SHTML"
[190]=>
string(3) "SIX"
[191]=>
string(5) "SIXEL"
[192]=>
string(12) "SPARSE-COLOR"
[193]=>
string(3) "SR2"
[194]=>
string(3) "SRF"
[195]=>
string(7) "STEGANO"
[196]=>
string(3) "SUN"
[197]=>
string(3) "SVG"
[198]=>
string(4) "SVGZ"
[199]=>
string(4) "TEXT"
[200]=>
string(3) "TGA"
[201]=>
string(9) "THUMBNAIL"
[202]=>
string(4) "TIFF"
[203]=>
string(6) "TIFF64"
[204]=>
string(4) "TILE"
[205]=>
string(3) "TIM"
[206]=>
string(3) "TTC"
[207]=>
string(3) "TTF"
[208]=>
string(3) "TXT"
[209]=>
string(4) "UBRL"
[210]=>
string(5) "UBRL6"
[211]=>
string(3) "UIL"
[212]=>
string(4) "UYVY"
[213]=>
string(3) "VDA"
[214]=>
string(5) "VICAR"
[215]=>
string(3) "VID"
[216]=>
string(4) "VIFF"
[217]=>
string(4) "VIPS"
[218]=>
string(3) "VST"
[219]=>
string(4) "WBMP"
[220]=>
string(4) "WEBP"
[221]=>
string(3) "WMF"
[222]=>
string(3) "WMV"
[223]=>
string(3) "WPG"
[224]=>
string(3) "X3F"
[225]=>
string(3) "XBM"
[226]=>
string(2) "XC"
[227]=>
string(3) "XCF"
[228]=>
string(3) "XPM"
[229]=>
string(3) "XPS"
[230]=>
string(2) "XV"
[231]=>
string(5) "YCbCr"
[232]=>
string(6) "YCbCrA"
[233]=>
string(3) "YUV"
}

csv header row as array key

I'm able to get the file into an array, but I'd like to get the key's to be the first row. Here's is the curl command:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url.com/download");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "X-App-Key: xxxxx";
$headers[] = "X-User-Key: yyyy";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $result));
return $data;
Here is the csv that is returned:
"Date,Campaign,Campaign Id,Impressions,Clicks,CTR,Platform Cost,Search Cost,Demographic Cost,Contextual Cost,Behavioral Cost,Geographic Cost,Segment Cost,Media Cost,CPM,Total Spend,ECPC,Click Sales,Click Leads,Click Signups,Click Other,View Sales,View Leads,View Signups,View Other,CPA,Weighted Actions 2017-05-16,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-18,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-19,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-20,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,2,,2.00 2017-05-28,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,1,,1.00 2017-06-02,Company,326606,,,,,,,,,,,,,,,0,0,0,0,0,0,0,1,,1.00 2017-05-10,Company,326606,16877,41,0.002429,0.770373,0.000000,0.0,0.000000,0.0,0.770373,0.000000,1.540785,3.081682,52.009548,1.268526,,,,,,,,,, 2017-05-11,Company,326606,17001,50,0.002941,0.764775,0.000000,0.0,0.000000,0.0,0.764775,0.000000,1.529592,3.059288,52.010956,1.040219,,,,,,,,,, 2017-05-12,Company,326606,16814,44,0.002617,0.773364,0.000000,0.0,0.000000,0.0,0.773364,0.000000,1.546763,3.093651,52.016652,1.182197,,,,,,,,,, 2017-05-13,Company,326606,16880,32,0.001896,0.770245,0.000000,0.0,0.000000,0.0,0.770245,0.000000,1.540520,3.081195,52.010570,1.625330,,,,,,,,,, 2017-05-14,Company,326606,17045,32,0.001877,0.762742,0.000000,0.0,0.000000,0.0,0.762742,0.000000,1.525543,3.051212,52.007907,1.625247,0,0,0,0,0,0,0,1,52.0079,1.00 2017-05-15,Company,326606,7294,10,0.001371,0.781126,0.000000,0.0,0.000000,0.0,0.781126,0.000000,1.562252,3.124683,22.791441,2.279144,,,,,,,,,, 2017-06-03,Company,559435,30186,42,0.001391,0.690422,0.690422,0.0,0.000000,0.0,0.000000,0.000000,1.380910,2.761773,83.366884,1.984926,0,0,0,1,0,0,0,1,41.6834,2.00 2017-06-04,Company,559435,29952,25,0.000835,0.695962,0.695962,0.0,0.000000,0.0,0.000000,0.000000,1.391983,2.783917,83.383894,3.335356,0,0,0,0,0,0,0,12,6.9487,12.00 2017-06-05,Company,559435,29863,39,0.001306,0.697854,0.697854,0.0,0.000000,0.0,0.000000,0.000000,1.395772,2.791494,83.362371,2.137497,0,0,0,4,2,1,0,15,3.7892,22.00 2017-06-06,Company,559435,29859,40,0.001340,0.698055,0.698055,0.0,0.000000,0.0,0.000000,0.000000,1.396160,2.792283,83.374777,2.084369,0,1,0,4,2,1,0,21,2.8750,29.00 2017-06-07,Company,559435,29968,22,0.000734,0.695653,0.695653,0.0,0.000000,0.0,0.000000,0.000000,1.391359,2.782683,83.391458,3.790521,0,0,0,1,0,0,0,25,3.2074,26.00 2017-06-08,Company,559435,29967,41,0.001368,0.695284,0.695284,0.0,0.000000,0.0,0.000000,0.000000,1.390634,2.781195,83.344075,2.032782,0,0,0,2,1,0,0,23,3.2055,26.00 2017-06-09,Company,559435,14689,8,0.000545,0.686755,0.686755,0.0,0.000000,0.0,0.000000,0.000000,1.373565,2.747041,40.351291,5.043911,0,0,0,0,0,2,0,21,1.7544,23.00 ,,,286395,426,0.001487,0.718754,0.471867,0.0,0.000000,0.0,0.246886,0.000000,1.437560,2.875126,823.421824,1.932915,0,1,0,12,5,4,0,129,5.4531,151.00
And the returned array is but I'd like "date" "clicks" to be used as the keys so I can simply call "$data[Click Lead]":
array(22) {
[0]=>
array(27) {
[0]=>
string(4) "Date"
[1]=>
string(8) "Campaign"
[2]=>
string(11) "Campaign Id"
[3]=>
string(11) "Impressions"
[4]=>
string(6) "Clicks"
[5]=>
string(3) "CTR"
[6]=>
string(13) "Platform Cost"
[7]=>
string(11) "Search Cost"
[8]=>
string(16) "Demographic Cost"
[9]=>
string(15) "Contextual Cost"
[10]=>
string(15) "Behavioral Cost"
[11]=>
string(15) "Geographic Cost"
[12]=>
string(12) "Segment Cost"
[13]=>
string(10) "Media Cost"
[14]=>
string(3) "CPM"
[15]=>
string(11) "Total Spend"
[16]=>
string(4) "ECPC"
[17]=>
string(11) "Click Sales"
[18]=>
string(11) "Click Leads"
[19]=>
string(13) "Click Signups"
[20]=>
string(11) "Click Other"
[21]=>
string(10) "View Sales"
[22]=>
string(10) "View Leads"
[23]=>
string(12) "View Signups"
[24]=>
string(10) "View Other"
[25]=>
string(3) "CPA"
[26]=>
string(16) "Weighted Actions"
}
[1]=>
array(27) {
[0]=>
string(10) "2017-05-16"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[2]=>
array(27) {
[0]=>
string(10) "2017-05-18"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[3]=>
array(27) {
[0]=>
string(10) "2017-05-19"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[4]=>
array(27) {
[0]=>
string(10) "2017-05-20"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "2"
[25]=>
string(0) ""
[26]=>
string(4) "2.00"
}
[5]=>
array(27) {
[0]=>
string(10) "2017-05-28"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(0) ""
[26]=>
string(4) "1.00"
}
[6]=>
array(27) {
[0]=>
string(10) "2017-06-02"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(0) ""
[4]=>
string(0) ""
[5]=>
string(0) ""
[6]=>
string(0) ""
[7]=>
string(0) ""
[8]=>
string(0) ""
[9]=>
string(0) ""
[10]=>
string(0) ""
[11]=>
string(0) ""
[12]=>
string(0) ""
[13]=>
string(0) ""
[14]=>
string(0) ""
[15]=>
string(0) ""
[16]=>
string(0) ""
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(0) ""
[26]=>
string(4) "1.00"
}
[7]=>
array(27) {
[0]=>
string(10) "2017-05-10"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16877"
[4]=>
string(2) "41"
[5]=>
string(8) "0.002429"
[6]=>
string(8) "0.770373"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.770373"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.540785"
[14]=>
string(8) "3.081682"
[15]=>
string(9) "52.009548"
[16]=>
string(8) "1.268526"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[8]=>
array(27) {
[0]=>
string(10) "2017-05-11"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "17001"
[4]=>
string(2) "50"
[5]=>
string(8) "0.002941"
[6]=>
string(8) "0.764775"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.764775"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.529592"
[14]=>
string(8) "3.059288"
[15]=>
string(9) "52.010956"
[16]=>
string(8) "1.040219"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[9]=>
array(27) {
[0]=>
string(10) "2017-05-12"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16814"
[4]=>
string(2) "44"
[5]=>
string(8) "0.002617"
[6]=>
string(8) "0.773364"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.773364"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.546763"
[14]=>
string(8) "3.093651"
[15]=>
string(9) "52.016652"
[16]=>
string(8) "1.182197"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[10]=>
array(27) {
[0]=>
string(10) "2017-05-13"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "16880"
[4]=>
string(2) "32"
[5]=>
string(8) "0.001896"
[6]=>
string(8) "0.770245"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.770245"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.540520"
[14]=>
string(8) "3.081195"
[15]=>
string(9) "52.010570"
[16]=>
string(8) "1.625330"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[11]=>
array(27) {
[0]=>
string(10) "2017-05-14"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(5) "17045"
[4]=>
string(2) "32"
[5]=>
string(8) "0.001877"
[6]=>
string(8) "0.762742"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.762742"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.525543"
[14]=>
string(8) "3.051212"
[15]=>
string(9) "52.007907"
[16]=>
string(8) "1.625247"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(7) "52.0079"
[26]=>
string(4) "1.00"
}
[12]=>
array(27) {
[0]=>
string(10) "2017-05-15"
[1]=>
string(25) "Company"
[2]=>
string(6) "326606"
[3]=>
string(4) "7294"
[4]=>
string(2) "10"
[5]=>
string(8) "0.001371"
[6]=>
string(8) "0.781126"
[7]=>
string(8) "0.000000"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.781126"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.562252"
[14]=>
string(8) "3.124683"
[15]=>
string(9) "22.791441"
[16]=>
string(8) "2.279144"
[17]=>
string(0) ""
[18]=>
string(0) ""
[19]=>
string(0) ""
[20]=>
string(0) ""
[21]=>
string(0) ""
[22]=>
string(0) ""
[23]=>
string(0) ""
[24]=>
string(0) ""
[25]=>
string(0) ""
[26]=>
string(0) ""
}
[13]=>
array(27) {
[0]=>
string(10) "2017-06-03"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "30186"
[4]=>
string(2) "42"
[5]=>
string(8) "0.001391"
[6]=>
string(8) "0.690422"
[7]=>
string(8) "0.690422"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.380910"
[14]=>
string(8) "2.761773"
[15]=>
string(9) "83.366884"
[16]=>
string(8) "1.984926"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "1"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(1) "1"
[25]=>
string(7) "41.6834"
[26]=>
string(4) "2.00"
}
[14]=>
array(27) {
[0]=>
string(10) "2017-06-04"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29952"
[4]=>
string(2) "25"
[5]=>
string(8) "0.000835"
[6]=>
string(8) "0.695962"
[7]=>
string(8) "0.695962"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.391983"
[14]=>
string(8) "2.783917"
[15]=>
string(9) "83.383894"
[16]=>
string(8) "3.335356"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "12"
[25]=>
string(6) "6.9487"
[26]=>
string(5) "12.00"
}
[15]=>
array(27) {
[0]=>
string(10) "2017-06-05"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29863"
[4]=>
string(2) "39"
[5]=>
string(8) "0.001306"
[6]=>
string(8) "0.697854"
[7]=>
string(8) "0.697854"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.395772"
[14]=>
string(8) "2.791494"
[15]=>
string(9) "83.362371"
[16]=>
string(8) "2.137497"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "4"
[21]=>
string(1) "2"
[22]=>
string(1) "1"
[23]=>
string(1) "0"
[24]=>
string(2) "15"
[25]=>
string(6) "3.7892"
[26]=>
string(5) "22.00"
}
[16]=>
array(27) {
[0]=>
string(10) "2017-06-06"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29859"
[4]=>
string(2) "40"
[5]=>
string(8) "0.001340"
[6]=>
string(8) "0.698055"
[7]=>
string(8) "0.698055"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.396160"
[14]=>
string(8) "2.792283"
[15]=>
string(9) "83.374777"
[16]=>
string(8) "2.084369"
[17]=>
string(1) "0"
[18]=>
string(1) "1"
[19]=>
string(1) "0"
[20]=>
string(1) "4"
[21]=>
string(1) "2"
[22]=>
string(1) "1"
[23]=>
string(1) "0"
[24]=>
string(2) "21"
[25]=>
string(6) "2.8750"
[26]=>
string(5) "29.00"
}
[17]=>
array(27) {
[0]=>
string(10) "2017-06-07"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29968"
[4]=>
string(2) "22"
[5]=>
string(8) "0.000734"
[6]=>
string(8) "0.695653"
[7]=>
string(8) "0.695653"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.391359"
[14]=>
string(8) "2.782683"
[15]=>
string(9) "83.391458"
[16]=>
string(8) "3.790521"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "1"
[21]=>
string(1) "0"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "25"
[25]=>
string(6) "3.2074"
[26]=>
string(5) "26.00"
}
[18]=>
array(27) {
[0]=>
string(10) "2017-06-08"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "29967"
[4]=>
string(2) "41"
[5]=>
string(8) "0.001368"
[6]=>
string(8) "0.695284"
[7]=>
string(8) "0.695284"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.390634"
[14]=>
string(8) "2.781195"
[15]=>
string(9) "83.344075"
[16]=>
string(8) "2.032782"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "2"
[21]=>
string(1) "1"
[22]=>
string(1) "0"
[23]=>
string(1) "0"
[24]=>
string(2) "23"
[25]=>
string(6) "3.2055"
[26]=>
string(5) "26.00"
}
[19]=>
array(27) {
[0]=>
string(10) "2017-06-09"
[1]=>
string(25) "Company"
[2]=>
string(6) "559435"
[3]=>
string(5) "14689"
[4]=>
string(1) "8"
[5]=>
string(8) "0.000545"
[6]=>
string(8) "0.686755"
[7]=>
string(8) "0.686755"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.000000"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.373565"
[14]=>
string(8) "2.747041"
[15]=>
string(9) "40.351291"
[16]=>
string(8) "5.043911"
[17]=>
string(1) "0"
[18]=>
string(1) "0"
[19]=>
string(1) "0"
[20]=>
string(1) "0"
[21]=>
string(1) "0"
[22]=>
string(1) "2"
[23]=>
string(1) "0"
[24]=>
string(2) "21"
[25]=>
string(6) "1.7544"
[26]=>
string(5) "23.00"
}
[20]=>
array(27) {
[0]=>
string(0) ""
[1]=>
string(0) ""
[2]=>
string(0) ""
[3]=>
string(6) "286395"
[4]=>
string(3) "426"
[5]=>
string(8) "0.001487"
[6]=>
string(8) "0.718754"
[7]=>
string(8) "0.471867"
[8]=>
string(3) "0.0"
[9]=>
string(8) "0.000000"
[10]=>
string(3) "0.0"
[11]=>
string(8) "0.246886"
[12]=>
string(8) "0.000000"
[13]=>
string(8) "1.437560"
[14]=>
string(8) "2.875126"
[15]=>
string(10) "823.421824"
[16]=>
string(8) "1.932915"
[17]=>
string(1) "0"
[18]=>
string(1) "1"
[19]=>
string(1) "0"
[20]=>
string(2) "12"
[21]=>
string(1) "5"
[22]=>
string(1) "4"
[23]=>
string(1) "0"
[24]=>
string(3) "129"
[25]=>
string(6) "5.4531"
[26]=>
string(6) "151.00"
}
[21]=>
array(1) {
[0]=>
NULL
}
}
Use array_combine and extend your code to:
$data = array_map("str_getcsv", preg_split('/\r*\n+|\r+/', $result));
$new_data = [];
// shift first element of $data, we will use it as keys.
$keys = array_shift($data);
foreach ($data as $item) {
// create key => value array
$new_data[] = array_combine($keys, $item);
}
Thanks to #Kazz - in case of warnings like
array_combine(): Both parameters should have an equal number of elements
you need to check if both elements are arrays and theirs sizes equals (with count(), for example).

PHP session saving array with POST values

First sorry for my English.
I have a weird problem using the php $_SESSION Object.
I spent 2 days without find the solution.
I am triying to save a multidimensional array that stores some post values.
I create an array with this values and then i create a multidimensional array containing this arrays.
Page 1 (setvalues in multi array ans save in session)-> GET -> Page 2 read the session.
My code Page 1:
First, save the post values into a object property and validate them.
public function validateData(){
$this->nombres=$_POST["nombre"];
$this->imp_nombres=$_POST["imp_nombre"];
$this->numeros=$_POST["numero"];
$this->imp_numeros=$_POST["imp_numero"];
$this->tallas=$_POST["talla"];
$this->cantidades=$_POST["cantidad"];
$this->productos=$_POST["products"];
$this->equipos=$_POST["equipo"];
if(WSI_Funtions::compareSizes($this->nombres,$this->imp_nombres,$this->numeros,$this->imp_numeros,$this->tallas,$this->cantidades,$this->productos,$this->equipos))
{
$this->isValidModel=true;
$this->saveProductsValues();
}
else{
$this->isValidModel=false;
$this->errorMessage="Los datos no son correctos. Los parametros no coinciden";
}
}
If data is ok, I save those values:
public function saveProductsValues()
{
$this->productsValues=array();
$this->productsValues["names"]=$this->nombres;
$this->productsValues["imp_nombres"]=$this->imp_nombres;
$this->productsValues["numeros"]=$this->numeros;
$this->productsValues["imp_numeros"]=$this->imp_numeros;
$this->productsValues["tallas"]=$this->tallas;
$this->productsValues["cantidades"]=$this->cantidades;
$this->productsValues["productos"]=$this->productos;
$this->productsValues["equipos"]=$this->equipos;
}
Then I save it in a session :
public function saveSessionValues()
{
$_SESSION['customer'] = $this->customerObject;
$_SESSION['productsValues'] =$this->productsValues;
echo var_dump($_SESSION['productsValues']);
}
The saveSessionValues echo print this:
array(8) { ["names"]=> array(12) { [0]=> string(0) "" [1]=> string(12) "ÁNGEL HDEZ." [2]=> string(11) "VUJASINOVIC" [3]=> string(4) "ABIA" [4]=> string(10) "MUTAKABBIR" [5]=> string(8) "PETROVIC" [6]=> string(5) "DOBOS" [7]=> string(4) "HOMS" [8]=> string(6) "CASTRO" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["imp_nombres"]=> array(12) { [0]=> string(0) "" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["numeros"]=> array(12) { [0]=> string(1) "7" [1]=> string(1) "8" [2]=> string(1) "9" [3]=> string(0) "" [4]=> string(2) "11" [5]=> string(2) "12" [6]=> string(2) "18" [7]=> string(2) "19" [8]=> string(2) "22" [9]=> string(1) "5" [10]=> string(2) "33" [11]=> string(0) "" } ["imp_numeros"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(0) "" [4]=> string(1) "1" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(0) "" } ["tallas"]=> array(12) { [0]=> string(4) "XXXL" [1]=> string(3) "XXL" [2]=> string(2) "XL" [3]=> string(3) "XXL" [4]=> string(3) "XXL" [5]=> string(3) "XXL" [6]=> string(4) "XXXL" [7]=> string(3) "XXL" [8]=> string(2) "XL" [9]=> string(4) "XXXL" [10]=> string(2) "XL" [11]=> string(3) "XXL" } ["cantidades"]=> array(12) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "1" [4]=> string(3) "145" [5]=> string(1) "1" [6]=> string(1) "1" [7]=> string(1) "1" [8]=> string(1) "1" [9]=> string(1) "1" [10]=> string(1) "1" [11]=> string(1) "1" } ["productos"]=> array(12) { [0]=> string(3) "109" [1]=> string(3) "109" [2]=> string(3) "109" [3]=> string(3) "109" [4]=> string(3) "109" [5]=> string(3) "109" [6]=> string(3) "109" [7]=> string(3) "109" [8]=> string(3) "109" [9]=> string(3) "109" [10]=> string(3) "109" [11]=> string(3) "109" } ["equipos"]=> array(12) { [0]=> string(7) "LEB ORO" [1]=> string(7) "LEB ORO" [2]=> string(7) "LEB ORO" [3]=> string(7) "LEB ORO" [4]=> string(7) "LEB ORO" [5]=> string(7) "LEB ORO" [6]=> string(12) "ES TALLA 4XL" [7]=> string(7) "LEB ORO" [8]=> string(7) "LEB ORO" [9]=> string(12) "ES TALLA 4XL" [10]=> string(7) "LEB ORO" [11]=> string(7) "LEB ORO" } }
My code Page 2 (php tags ommitted):
if (!isset($_SESSION)) { session_start(); }
echo var_dump($_SESSION['productsValues']);
This echo print the next value:
array(8) { ["names"]=> NULL ["imp_nombres"]=> NULL ["numeros"]=> NULL ["imp_numeros"]=> NULL ["tallas"]=> NULL ["cantidades"]=> NULL ["productos"]=> NULL ["equipos"]=> NULL }
The first level array exists, because the subarrays keys are printed, but all the second level arrays are NULL..
Maybe is for use the $_POST value??
I had try to encode the values of the $_POST object, saving only a json string instead of saving a object with the same result, the first nodes in the JSON are the keys of the arrays but the values are "NULL"
Any help please??
Thanks!!
You are over writing the values. Try with -
$_SESSION['productsValues'][] = $this->productsValues;

Categories