Obtener valores de objetos php en una matriz
Frecuentes
Visto 68 veces
-2
I want what is output from the initial echo $zip
to be stuffed into an array as a simple integer stack... I have tried []
,{}
and a variety of other accessors... Thanks again!
Yo tengo:
$userZip = new ZipCode($userZip);
$theZips = array();
foreach ($userZip->getZipsInRange(0, 10) as $miles => $zip) {
echo $zip . '<BR>';
$theZips = $zip;
}
print_r($theZips);
// print_r($theZips) output:
ZipCode Object ( [zip_code_id:ZipCode:private] => 33816 [zip_code:ZipCode:private] => 21115 [lat:ZipCode:private] => 42.48 [lon:ZipCode:private] => -83.02 [city:ZipCode:private] => CENTER Ville [county:ZipCode:private] => [area_code:ZipCode:private] => [time_zone:ZipCode:private] => [state_prefix:ZipCode:private] => VA [state_name:ZipCode:private] => [mysql_table] => zip_code [mysql_conn] => [mysql_row:ZipCode:private] => Array ( [miles] => 8.88798662376604 [zip_code_id] => 33816 [zip_code] => 21119 [city] => City [state_prefix] => VA [lat] => 42.48 [lon] => -83.02 ) [print_name:ZipCode:private] => 48015 [location_type:ZipCode:private] => [miles] => 8.88798662376604 )
// UPDATED// thanks tried that but I get objects
print_R($theZips);
// producción:
Array ( [0] => ZipCode Object ( [zip_code_id:ZipCode:private] => 34026 [zip_code:ZipCode:private] => 21115 [lat:ZipCode:private] => 42.58 [lon:ZipCode:private] => -82.91 [city:ZipCode:private] => City Ville [county:ZipCode:private] => [area_code:ZipCode:private] => [time_zone:ZipCode:private] => [state_prefix:ZipCode:private] => VA [state_name:ZipCode:private] => [mysql_table] => zip_code [mysql_conn] => [mysql_row:ZipCode:private] => Array ( [miles] => 0.000225049859756069 [zip_code_id] => 34026 [zip_code] => 21115 [city] => City Ville [state_prefix] => VA [lat] => 42.58 [lon] => -82.91 )
[print_name:ZipCode:private] => 21119
[location_type:ZipCode:private] =>
[miles] => 0.000225049859756069
)
1 Respuestas
0
foreach ($userZip->getZipsInRange(0, 10) as $miles => $zip) {
echo $zip . '<BR>';
$theZips[] = $zip; //push $zip into $theZips array
}
Respondido el 11 de Septiembre de 13 a las 23:09
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas php arrays object or haz tu propia pregunta.
thanks but that does not seem to be getting the desired results, it appears to be an object array - user2679805