我希望从初始echo $zip
输出的内容作为一个简单的整数堆栈填充到数组中...我尝试过[]
,{}
和其他各种访问器...再次感谢!
我有:
$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 //感谢尝试过,但我得到了对象
的print_r($ theZips);
//输出:
阵 ( [0] =&gt; ZipCode对象 ( [zip_code_id:ZipCode:private] =&gt; 34026 [zip_code:ZipCode:private] =&gt; 21115 [lat:ZipCode:private] =&gt; 42.58 [lon:ZipCode:private] =&gt; -82.91 [city:ZipCode:private] =&gt;城市维尔 [county:ZipCode:private] =&gt; [area_code:ZipCode:private] =&gt; [time_zone:ZipCode:private] =&gt; [state_prefix:ZipCode:private] =&gt; VA [state_name:ZipCode:private] =&gt; [mysql_table] =&gt;邮政编码 [mysql_conn] =&gt; [mysql_row:ZipCode:private] =&gt;排列 ( [miles] =&gt; 0.000225049859756069 [zip_code_id] =&gt; 34026 [zip_code] =&gt; 21115 [city] =&gt;城市维尔 [state_prefix] =&gt; VA [lat] =&gt; 42.58 [lon] =&gt; -82.91 )
[print_name:ZipCode:private] => 21119
[location_type:ZipCode:private] =>
[miles] => 0.000225049859756069
)
答案 0 :(得分:0)
foreach ($userZip->getZipsInRange(0, 10) as $miles => $zip) {
echo $zip . '<BR>';
$theZips[] = $zip; //push $zip into $theZips array
}