PHP - get values from an array inside an array - php

Hi I have this huge array:
array(14) {
["imagen-profesor"]=>
array(8) {
["id"]=>
string(15) "imagen-profesor"
["slug"]=>
string(15) "imagen-profesor"
["type"]=>
string(5) "image"
["name"]=>
string(15) "Imagen profesor"
["description"]=>
string(17) "Foto del profesor"
["data"]=>
array(8) {
["slug-pre-save"]=>
string(15) "imagen-profesor"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
["validate"]=>
array(1) {
["url2"]=>
array(3) {
["active"]=>
string(1) "1"
["message"]=>
string(60) "Please enter a valid URL address pointing to the image file."
["suppress_for_cred"]=>
bool(true)
}
}
}
["meta_key"]=>
string(20) "wpcf-imagen-profesor"
["meta_type"]=>
string(8) "usermeta"
}
["grados-academicos"]=>
array(8) {
["id"]=>
string(17) "grados-academicos"
["slug"]=>
string(17) "grados-academicos"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(18) "Grados académicos"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(17) "grados-academicos"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(22) "wpcf-grados-academicos"
["meta_type"]=>
string(8) "usermeta"
}
["experiencia-profesional"]=>
array(8) {
["id"]=>
string(23) "experiencia-profesional"
["slug"]=>
string(23) "experiencia-profesional"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(23) "Experiencia profesional"
["description"]=>
string(46) "Por favor coloca aquí experiencia profesional"
["data"]=>
array(5) {
["slug-pre-save"]=>
string(23) "experiencia-profesional"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(28) "wpcf-experiencia-profesional"
["meta_type"]=>
string(8) "usermeta"
}
["areas-de-interes"]=>
array(8) {
["id"]=>
string(16) "areas-de-interes"
["slug"]=>
string(16) "areas-de-interes"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(18) "Áreas de interés"
["description"]=>
string(22) "Intereses del profesor"
["data"]=>
array(5) {
["slug-pre-save"]=>
string(16) "areas-de-interes"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(21) "wpcf-areas-de-interes"
["meta_type"]=>
string(8) "usermeta"
}
["cursos-relevantes"]=>
array(8) {
["id"]=>
string(17) "cursos-relevantes"
["slug"]=>
string(17) "cursos-relevantes"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(17) "Cursos relevantes"
["description"]=>
string(7) "Cursos "
["data"]=>
array(5) {
["slug-pre-save"]=>
string(17) "cursos-relevantes"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(22) "wpcf-cursos-relevantes"
["meta_type"]=>
string(8) "usermeta"
}
["articulos"]=>
array(8) {
["id"]=>
string(9) "articulos"
["slug"]=>
string(9) "articulos"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(10) "Artículos"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(9) "articulos"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(14) "wpcf-articulos"
["meta_type"]=>
string(8) "usermeta"
}
["areas-academicas"]=>
array(8) {
["id"]=>
string(16) "areas-academicas"
["slug"]=>
string(16) "areas-academicas"
["type"]=>
string(6) "select"
["name"]=>
string(18) "Áreas académicas"
["description"]=>
string(0) ""
["data"]=>
array(6) {
["slug-pre-save"]=>
string(16) "areas-academicas"
["options"]=>
array(12) {
["wpcf-fields-select-option-96129381b0cc289dd28e00d98f8c15b0-1"]=>
array(2) {
["title"]=>
string(23) "Análisis de decisiones"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-f320b41329b42d462bd08eb7961f2c65-1"]=>
array(2) {
["title"]=>
string(17) "Comercialización"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-f6b63eb3926b7de2462225998e09cc13-1"]=>
array(2) {
["title"]=>
string(32) "Control e información directiva"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-b2610684e6f824fd687a74d3be7bcabe-1"]=>
array(2) {
["title"]=>
string(21) "Dirección financiera"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-d2c3f7b635105db769c4772a15d5cec2-1"]=>
array(2) {
["title"]=>
string(25) "Dirección de operaciones"
["value"]=>
string(1) "5"
}
["wpcf-fields-select-option-f14bad56bc815fa8060ae231ccb8a217-1"]=>
array(2) {
["title"]=>
string(22) "Dirección de personal"
["value"]=>
string(1) "6"
}
["wpcf-fields-select-option-c6114cc9883ef2a4c8d23d9985fd41fc-1"]=>
array(2) {
["title"]=>
string(15) "Empresa-familia"
["value"]=>
string(1) "7"
}
["wpcf-fields-select-option-6378fcaa75be017d5cddec1f4c837bba-1"]=>
array(2) {
["title"]=>
string(18) "Entorno económico"
["value"]=>
string(1) "8"
}
["wpcf-fields-select-option-48713712cd807bd0920369faaea72630-1"]=>
array(2) {
["title"]=>
string(26) "Entorno político y social"
["value"]=>
string(1) "9"
}
["wpcf-fields-select-option-35c50a5e264b2951ccbd9a83f0d52185-1"]=>
array(2) {
["title"]=>
string(13) "Factor humano"
["value"]=>
string(2) "10"
}
["wpcf-fields-select-option-bdac1a39ab699e74fbffd3b6a9aa85be-1"]=>
array(2) {
["title"]=>
string(20) "Política de empresa"
["value"]=>
string(2) "11"
}
["default"]=>
string(10) "no-default"
}
["validate"]=>
array(1) {
["required"]=>
array(3) {
["active"]=>
string(1) "1"
["value"]=>
string(4) "true"
["message"]=>
string(25) "Por favor, elige el área"
}
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(21) "wpcf-areas-academicas"
["meta_type"]=>
string(8) "usermeta"
}
["calendario"]=>
array(8) {
["id"]=>
string(10) "calendario"
["slug"]=>
string(10) "calendario"
["type"]=>
string(4) "date"
["name"]=>
string(10) "Calendario"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(10) "calendario"
["placeholder"]=>
string(0) ""
["date_and_time"]=>
string(4) "date"
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(15) "wpcf-calendario"
["meta_type"]=>
string(8) "usermeta"
}
["duracion"]=>
array(8) {
["id"]=>
string(8) "duracion"
["slug"]=>
string(8) "duracion"
["type"]=>
string(8) "textarea"
["name"]=>
string(9) "Duración"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(8) "duracion"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(13) "wpcf-duracion"
["meta_type"]=>
string(8) "usermeta"
}
["fechas"]=>
array(8) {
["id"]=>
string(6) "fechas"
["slug"]=>
string(6) "fechas"
["type"]=>
string(8) "textarea"
["name"]=>
string(6) "Fechas"
["description"]=>
string(0) ""
["data"]=>
array(7) {
["slug-pre-save"]=>
string(6) "fechas"
["placeholder"]=>
string(0) ""
["user_default_value"]=>
string(0) ""
["repetitive"]=>
string(1) "0"
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(11) "wpcf-fechas"
["meta_type"]=>
string(8) "usermeta"
}
["contacto"]=>
array(8) {
["id"]=>
string(8) "contacto"
["slug"]=>
string(8) "contacto"
["type"]=>
string(7) "wysiwyg"
["name"]=>
string(8) "Contacto"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(8) "contacto"
["user_default_value"]=>
string(0) ""
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(13) "wpcf-contacto"
["meta_type"]=>
string(8) "usermeta"
}
["areas-academicas-2"]=>
array(8) {
["id"]=>
string(18) "areas-academicas-2"
["slug"]=>
string(18) "areas-academicas-2"
["type"]=>
string(6) "select"
["name"]=>
string(24) "Segunda área académica"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(18) "areas-academicas-2"
["options"]=>
array(12) {
["wpcf-fields-select-option-a84588db3f03c2837345f94adfa18588-1"]=>
array(2) {
["title"]=>
string(23) "Análisis de decisiones"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-5a20ef6e60591caaf5bec848cf43cec0-1"]=>
array(2) {
["title"]=>
string(17) "Comercialización"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-3b00b7d1d1040c63c3512a7e52446443-1"]=>
array(2) {
["title"]=>
string(32) "Control e información directiva"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-da90a64b9b2bf7becfbec27c9c4025da-1"]=>
array(2) {
["title"]=>
string(21) "Dirección financiera"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-65c40a4ea4cde81d6fb7b5bbe1c73282-1"]=>
array(2) {
["title"]=>
string(25) "Dirección de operaciones"
["value"]=>
string(1) "5"
}
["wpcf-fields-select-option-3b7a56cdb15cef8028daf43082269339-1"]=>
array(2) {
["title"]=>
string(22) "Dirección de personal"
["value"]=>
string(1) "6"
}
["wpcf-fields-select-option-6eded9521556a27a4cf4465c82f0a203-1"]=>
array(2) {
["title"]=>
string(15) "Empresa-familia"
["value"]=>
string(1) "7"
}
["wpcf-fields-select-option-5102092609e13386bfadc0ed367591b7-1"]=>
array(2) {
["title"]=>
string(18) "Entorno económico"
["value"]=>
string(1) "8"
}
["wpcf-fields-select-option-e1aadcfe82cc3389a57288a85ed45ff6-1"]=>
array(2) {
["title"]=>
string(26) "Entorno político y social"
["value"]=>
string(1) "9"
}
["wpcf-fields-select-option-6440b6d9a60739b88dacaafae2bccaa9-1"]=>
array(2) {
["title"]=>
string(13) "Factor humano"
["value"]=>
string(2) "10"
}
["wpcf-fields-select-option-2d081231584de301011755851f93b246-1"]=>
array(2) {
["title"]=>
string(20) "Política de empresa"
["value"]=>
string(2) "11"
}
["default"]=>
string(10) "no-default"
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(23) "wpcf-areas-academicas-2"
["meta_type"]=>
string(8) "usermeta"
}
["cargo-profesor"]=>
array(8) {
["id"]=>
string(14) "cargo-profesor"
["slug"]=>
string(14) "cargo-profesor"
["type"]=>
string(6) "select"
["name"]=>
string(14) "Cargo Profesor"
["description"]=>
string(36) "Selecciona un cargo para el profesor"
["data"]=>
array(6) {
["slug-pre-save"]=>
string(14) "cargo-profesor"
["options"]=>
array(5) {
["wpcf-fields-select-option-2a9da69d4d39817ac2a4b687ac49dc27-1"]=>
array(2) {
["title"]=>
string(18) "Director del área"
["value"]=>
string(1) "4"
}
["wpcf-fields-select-option-b7ae4c59b346a60a6680338c9c44c456-1"]=>
array(2) {
["title"]=>
string(8) "Profesor"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-51a473bf339e2669511accaa90983fb0-1"]=>
array(2) {
["title"]=>
string(17) "Profesor invitado"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-734e5707d3253ded0bf0d972f1c56afe-1"]=>
array(2) {
["title"]=>
string(6) "Decano"
["value"]=>
string(1) "3"
}
["default"]=>
string(10) "no-default"
}
["validate"]=>
array(1) {
["required"]=>
array(3) {
["active"]=>
string(1) "1"
["value"]=>
string(4) "true"
["message"]=>
string(23) "This field is required."
}
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(19) "wpcf-cargo-profesor"
["meta_type"]=>
string(8) "usermeta"
}
["segundo-cargo"]=>
array(8) {
["id"]=>
string(13) "segundo-cargo"
["slug"]=>
string(13) "segundo-cargo"
["type"]=>
string(6) "select"
["name"]=>
string(13) "Segundo cargo"
["description"]=>
string(0) ""
["data"]=>
array(5) {
["slug-pre-save"]=>
string(13) "segundo-cargo"
["options"]=>
array(5) {
["wpcf-fields-select-option-30ef69a1ba17b84f26edcee1404746f4-1"]=>
array(2) {
["title"]=>
string(18) "Director del área"
["value"]=>
string(1) "1"
}
["wpcf-fields-select-option-8b8dbd4c42d2e4d61053f442e82a88be-1"]=>
array(2) {
["title"]=>
string(8) "Profesor"
["value"]=>
string(1) "2"
}
["wpcf-fields-select-option-862f1fbf0e317265cf544b754d6fa3f0-1"]=>
array(2) {
["title"]=>
string(17) "Profesor invitado"
["value"]=>
string(1) "3"
}
["wpcf-fields-select-option-d49829cdb8f8aaae8af93f30f220ca86-1"]=>
array(2) {
["title"]=>
string(6) "Decano"
["value"]=>
string(1) "4"
}
["default"]=>
string(10) "no-default"
}
["custom_use"]=>
string(0) ""
["conditional_display"]=>
array(0) {
}
["disabled_by_type"]=>
int(0)
}
["meta_key"]=>
string(18) "wpcf-segundo-cargo"
["meta_type"]=>
string(8) "usermeta"
}
}
I just want to get this value: Análisis de decisiones, Comercialización, Control e información directiva, Dirección financiera, "Dirección de operaciones, Dirección de personal, Empresa-familia, Entorno económico, Entorno político y social, Factor humano, Política de empresa.
I mean what is inside areas-academicas
I'm using nested foreach but nothing:
foreach ($un as $key => $value)
{
if ( $key === "areas-academicas" )
{
echo "Llave: " . $key . " => ";
//echo $value;
foreach ( $value as $key2 => $value2 )
{
echo "Llave2: " . $key2 . "<br />" . "valor2: " . $value2;
foreach ($value2 as $key3 => $value3)
{
echo "Llave3: " . $key3 . "<br />" . "valor3: " . $value3;
}
}
}
}
What could be an easy way to get those values? thanks.

If I don't messed up with your nesting this should work. If it doesn't just fix the path inside the foreach.
$data = array(...); // the array you posted
foreach ($data["areas-academicas"]["data"]["options"] as $area) {
echo $area["title"];
}
The bottom line is you can start the iteration from any level, you don't have to begin at the top necessarily.

Looking at the Array it appears that youre only interested in two of arrays at the top level:
$un["areas-academicas"]
$un["areas-academicas-2"]
Then you are looking for specific values, titles of the options of the data, in the nested structure underneath these two:
$un["areas-academicas"]['data']['options'][....]['title']
You can probably limit the iterations of your loop by using the uniform structure of these arrays. But I will assume you wish to loop through the top level array for keys containing "areas-academicas":
$titles = array();
foreach ($un as $key => $value){
if(strpos($key, 'areas-academicas') == false){ continue; }
foreach($value['data']['options'] as $val){
$titles[] = $val['title'];
}
}
This loop should collect all the option titles from the areas-academicas arrays but is reliant on the idea that the nested structure will be uniform for each instance of the areas-academicas key in the top level array. Hope this helps

Related

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;
}
}

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.

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.

JSON parsing in php to display the server response sabre

After making the authentication in sabre from php and make an inquiry about a flight, the response is a JSON string that I can not decipher, someone aid me, as I can show this readable string in php for my project.
part of the code, thanks for your help
object(SharedContext)#3 (1) {
["results":"SharedContext":private]=>
array(7) {
["SECURITY"]=>``
NULL
["origin"]=>
string(3) "MTR"
["destination"]=>
string(3) "BOG"
["departureDate"]=>
string(10) "2016-06-10"
["LeadPriceCalendar"]=>
object(stdClass)#6 (5) {
["status"]=>
string(8) "Complete"
["type"]=>
string(11) "Application"
["errorCode"]=>
string(20) "WARN.RAF.APPLICATION"
["timeStamp"]=>
string(25) "2016-06-03T22:04:40+00:00"
["message"]=>
string(21) "No results were found"
}
["InstaFlight"]=>
NULL
["BargainFinderMax"]=>
object(stdClass)#4 (2) {
["OTA_AirLowFareSearchRS"]=>
object(stdClass)#10 (11) {
["PricedItinCount"]=>
int(6)
["BrandedOneWayItinCount"]=>
int(0)
["SimpleOneWayItinCount"]=>
int(0)
["DepartedItinCount"]=>
int(0)
["SoldOutItinCount"]=>
int(0)
["AvailableItinCount"]=>
int(0)
["Version"]=>
string(5) "1.8.6"
["Success"]=>
object(stdClass)#11 (0) {
}
["Warnings"]=>
object(stdClass)#12 (1) {
["Warning"]=>
array(4) {
[0]=>
object(stdClass)#13 (5) {
["Type"]=>
string(12) "WORKERTHREAD"
["ShortText"]=>
string(19) "1750772809123328107"
["Code"]=>
string(13) "TRANSACTIONID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[1]=>
object(stdClass)#14 (5) {
["Type"]=>
string(6) "SERVER"
["ShortText"]=>
string(5) "27037"
["Code"]=>
string(9) "TTFHLC702"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[2]=>
object(stdClass)#15 (5) {
["Type"]=>
string(7) "DEFAULT"
["ShortText"]=>
string(5) "13330"
["Code"]=>
string(6) "RULEID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
[3]=>
object(stdClass)#16 (5) {
["Type"]=>
string(3) "DRE"
["ShortText"]=>
string(5) "13291"
["Code"]=>
string(6) "RULEID"
["MessageClass"]=>
string(1) "I"
["content"]=>
string(0) ""
}
}
}
["PricedItineraries"]=>
object(stdClass)#17 (1) {
["PricedItinerary"]=>
array(6) {
[0]=>
object(stdClass)#18 (5) {
["SequenceNumber"]=>
int(1)
["AirItinerary"]=>
object(stdClass)#19 (2) {
["DirectionInd"]=>
string(6) "OneWay"
["OriginDestinationOptions"]=>
object(stdClass)#20 (1) {
["OriginDestinationOption"]=>
array(1) {
[0]=>
object(stdClass)#21 (2) {
["ElapsedTime"]=>
int(76)
["FlightSegment"]=>
array(1) {
[0]=>
object(stdClass)#22 (15) {
["DepartureDateTime"]=>
string(19) "2016-06-10T08:38:00"
["ArrivalDateTime"]=>
string(19) "2016-06-10T09:54:00"
["StopQuantity"]=>
int(0)
["FlightNumber"]=>
string(4) "3193"
["ResBookDesigCode"]=>
string(1) "Q"
["ElapsedTime"]=>
int(76)
["DepartureAirport"]=>
object(stdClass)#23 (2) {
["LocationCode"]=>
string(3) "MTR"
["content"]=>
string(0) ""
}
["ArrivalAirport"]=>
object(stdClass)#24 (3) {
["LocationCode"]=>
string(3) "BOG"
["TerminalID"]=>
string(1) "1"
["content"]=>
string(0) ""
}
["OperatingAirline"]=>
object(stdClass)#25 (4) {
["CompanyShortName"]=>
string(26) "LAN COLOMBIA AIRLINES S.A."
["Code"]=>
string(2) "LA"
["FlightNumber"]=>
string(4) "3193"
["content"]=>
string(0) ""
}
["Equipment"]=>
array(1) {
[0]=>
object(stdClass)#26 (2) {
["AirEquipType"]=>
string(3) "320"
["content"]=>
string(0) ""
}
}
["MarketingAirline"]=>
object(stdClass)#27 (2) {
["Code"]=>
string(2) "LA"
["content"]=>
string(0) ""
}
["MarriageGrp"]=>
string(1) "O"
["DepartureTimeZone"]=>
object(stdClass)#28 (1) {
["GMTOffset"]=>
float(-5)
}
["ArrivalTimeZone"]=>
object(stdClass)#29 (1) {
["GMTOffset"]=>
float(-5)
}
["TPA_Extensions"]=>
object(stdClass)#30 (1) {
["eTicket"]=>
object(stdClass)#31 (1) {
["Ind"]=>
bool(true)
}
}
}
}
}
}
}
}

How to get object like value:item:private from PHP Array

I have the array like this:
} ["items":"Jcart":private]=> array(3) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
[2]=>
string(7) "ABC-123" }
How to get the "items" values in a php variable?
///////
Te complete object is:
object(Jcart)#1 (8) {
["config"]=>
array(12) {
["jcartPath"]=>
string(6) "jcart/"
["checkoutPath"]=>
string(12) "checkout.php"
["item"]=>
array(6) {
["id"]=>
string(10) "my-item-id"
["name"]=>
string(12) "my-item-name"
["price"]=>
string(13) "my-item-price"
["qty"]=>
string(11) "my-item-qty"
["url"]=>
string(11) "my-item-url"
["add"]=>
string(13) "my-add-button"
}
["paypal"]=>
array(5) {
["id"]=>
string(38) "seller_1282188508_biz#conceptlogic.com"
["https"]=>
bool(true)
["sandbox"]=>
bool(false)
["returnUrl"]=>
string(0) ""
["notifyUrl"]=>
string(0) ""
}
["currencyCode"]=>
string(3) "USD"
["csrfToken"]=>
bool(false)
["text"]=>
array(14) {
["cartTitle"]=>
string(13) "Shopping Cart"
["singleItem"]=>
string(4) "Item"
["multipleItems"]=>
string(5) "Items"
["subtotal"]=>
string(8) "Subtotal"
["update"]=>
string(6) "update"
["checkout"]=>
string(8) "checkout"
["checkoutPaypal"]=>
string(20) "Checkout with PayPal"
["removeLink"]=>
string(6) "remove"
["emptyButton"]=>
string(5) "empty"
["emptyMessage"]=>
string(19) "Your cart is empty!"
["itemAdded"]=>
string(11) "Item added!"
["priceError"]=>
string(21) "Invalid price format!"
["quantityError"]=>
string(38) "Item quantities must be whole numbers!"
["checkoutError"]=>
string(34) "Your order could not be processed!"
}
["button"]=>
array(4) {
["checkout"]=>
string(0) ""
["paypal"]=>
string(0) ""
["update"]=>
string(0) ""
["empty"]=>
string(0) ""
}
["tooltip"]=>
bool(true)
["decimalQtys"]=>
bool(false)
["decimalPlaces"]=>
int(1)
["priceFormat"]=>
array(3) {
["decimals"]=>
int(2)
["dec_point"]=>
string(1) "."
["thousands_sep"]=>
string(1) ","
}
}
["items":"Jcart":private]=>
array(2) {
[0]=>
string(1) "3"
[1]=>
string(1) "2"
}
["names":"Jcart":private]=>
array(2) {
[3]=>
string(12) "Hockey Stick"
[2]=>
string(13) "Baseball Mitt"
}
["prices":"Jcart":private]=>
array(2) {
[3]=>
string(5) "33.25"
[2]=>
string(5) "19.50"
}
["qtys":"Jcart":private]=>
array(2) {
[3]=>
string(1) "1"
[2]=>
string(2) "20"
}
["urls":"Jcart":private]=>
array(2) {
[3]=>
string(15) "http://bing.com"
[2]=>
string(16) "http://yahoo.com"
}
["subtotal":"Jcart":private]=>
float(423.25)
["itemCount":"Jcart":private]=>
int(21)
}
I just need the values in ["items":"Jcart":private]
I assume you got this by casting an object to an array. If that's the case, you shouldn't be doing that! The property is private because you're not supposed to access it directly because it's not a public API. The object should have a public method which you're supposed to call instead, that's the public API. Something like $foo->getItems() or such. Read the documentation and/or source code.

Categories