1

此代码将不起作用任何人都可以创建解决方案吗?

<?php
  //Assigns 10 to test1. 20 to test2. 30 to test3.
  $array1 = array(10 => "test1", 20 => "test2", 30 => "test3");  
  //Creates a blank array.
  $blank = new ArrayObject(array()); 

  $blank->append(array("20")); //Adds the value 20, to the blank array.
  $blank->append(array("30")); //Adds the value 30, to the blank array.

  print($array1[$blank[0]]); // should print "test2"
  print($array1[$blank[1]]); // should print "test3"
?>
4

1 回答 1

1

您是否在寻找:

<?php
  //Assigns 10 to test1. 20 to test2. 30 to test3.
  $array1 = array(10 => "test1", 20 => "test2", 30 => "test3");  
  //Creates a blank array.
  $blank = new ArrayObject();

  $blank->append(array("20")); //Adds the value 20, to the blank array.
  $blank->append(array("30")); //Adds the value 30, to the blank array.

  print($array1[$blank[0][0]]); // should print "test2"
  print($array1[$blank[1][0]]); // should print "test3"
?>

在这里,$blank将是多维的。

http://ideone.com/XsgnSz

或者更有可能:

<?php
  //Assigns 10 to test1. 20 to test2. 30 to test3.
  $array1 = array(10 => "test1", 20 => "test2", 30 => "test3");  
  //Creates a blank array.
  $blank = new ArrayObject();

  $blank->append("20"); //Adds the value 20, to the blank array.
  $blank->append("30"); //Adds the value 30, to the blank array.

  print($array1[$blank[0]]); // should print "test2"
  print($array1[$blank[1]]); // should print "test3"
?>

http://ideone.com/eyXL6v

于 2012-12-28T02:13:22.340 回答