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 に答える