4

我想要做

<?php 
$str = "I want to access 2nd or 3rd index in one line";
echo explode(" ",$str)[2];
?>

我们可以使用轻松访问第一个索引

stristr($str," ",true);  //For php version >= 5.3

或者

$foo = array_shift(explode(':', $foo));

或者

list($str) = explode(" ", $str);

如何在一行中访问特定索引 [1]、[2] 或 [3]?

4

3 回答 3

3

5.4+

<?php echo explode(" ","I want to access 2nd or 3rd index in one line")[2]; ?>
于 2013-06-13T07:13:16.187 回答
0

第二次

strtok($string, " "); echo strtok(" ");

或第三

strtok($string, " "); strtok(" "); echo strtok(" ");
于 2013-06-13T07:18:01.333 回答
-1

像这样尝试获取特定的索引值

<?php 
  $str = "Iam want to access 2nd or 3rd index in one line";
  $val = explode(" ",$str);
  echo $val[3];
?>
于 2013-06-13T07:25:11.600 回答