如何将赋值赋给FOR LOOP中的数组

时间:2013-09-03 12:22:10

标签: php arrays

如何将输出/派生值分配给FOR LOOP中的数组

$num = count($email);
  for($i=0; $i < $num; $i++){
      $result = do_post_request("http://api.mysite/api/IsActiveAccount?email=". $email[$i], null);
      $status = str_replace('{"result":', "", $result);
      $status = str_replace('}', "", $status);
      echo  $email[$i] ;
   }

OUTPUT---->
  red@yahoo.com
  blue@yahoo.com
  yellow@yahoo.com
  white@yahoo.com

如何在阵列内分配/放置?像这个。

  $value = array("red@yahoo.com","blue@yahoo.com","yellow@yahoo.com", "white@yahoo.com")

3 个答案:

答案 0 :(得分:2)

尝试将$email[$i]分配给$value,就像

一样
for($i=0; $i < $num; $i++){
  $result = do_post_request("http://api.mysite/api/IsActiveAccount?email=". $email[$i], null);
  $status = str_replace('{"result":', "", $result);
  $status = str_replace('}', "", $status);
  $value[] = $email[$i] ;    // Here it will assign $email in $value as an array 
}
print_r($value);

答案 1 :(得分:0)

$value = array();

for($i=0; $i < $num; $i++){

 $result = do_post_request("http://api.mysite/api/IsActiveAccount?email=". $email[$i], null);
$status = str_replace('{"result":', "", $result);
$status = str_replace('}', "", $status);
$value[] = $email[$i] ;

}

print_r($value);

答案 2 :(得分:0)

不是JSON吗?

 $values = array();
 for($i=0; $i < $num; $i++){
    $result = do_post_request("http://api.mysite/api/IsActiveAccount?email=". $email[$i], null);
    $result = json_decode($result);
    $values[] = $result['result'];
 }