Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP通过引用传递数组元素_Php_Regex_Pass By Reference - Fatal编程技术网

PHP通过引用传递数组元素

PHP通过引用传递数组元素,php,regex,pass-by-reference,Php,Regex,Pass By Reference,我有两个数组,一个索引数组和一个关联数组。我的问题归结为,如何将关联数组的引用传递给edit类。这样,当有更多的书和电影时,我可以循环浏览,清理所有的isbn,而不触摸电影。我遇到的问题是在for循环中传递引用 $i = new intro(); class intro{ public function __construct(){ $index = array(array("book", "regex"), array("movie", "regex")); $assoc

我有两个数组,一个索引数组和一个关联数组。我的问题归结为,如何将关联数组的引用传递给edit类。这样,当有更多的书和电影时,我可以循环浏览,清理所有的isbn,而不触摸电影。我遇到的问题是在for循环中传递引用

$i = new intro();

class intro{
  public function __construct(){
    $index = array(array("book", "regex"), array("movie", "regex"));
    $assoc = array(array("book"=>"freeBSD", "isbn"=>"01-2345-6789"), 
                   array("movie"=>"batman", "date"=>"10-10-1995");

    for($x = 0; $x < count($index); $x++){
      if($index[$x]["book"] == key($assoc)){
        edit::modify(current($assoc)); //I WANT TO PASS THE REFERENCE NOT VALUE
      }                                //current(&$assoc) DOES NOT WORK 
      next($assoc);
    }
  }
}

class edit{
  public function modify(&$isbn){
    $pattern = "/[^0-9]*/";
    $isbn = preg_replace($pattern, "", $isbn);
  }
}
$i=newintro();
课堂介绍{
公共函数构造(){
$index=数组(数组(“book”、“regex”)、数组(“movie”、“regex”);
$assoc=数组(数组(“book”=>“freeBSD”、“isbn”=>“01-2345-6789”),
数组(“电影”=>“蝙蝠侠”,“日期”=>“1995年10月10日”);
对于($x=0;$x
将其发布在此处作为参考,因为这已在注释中解决

执行
和$assoc[key($assoc)]
将解决问题

for($x = 0; $x < count($index); $x++){
  if($index[$x]["book"] == key($assoc)){
    edit::modify(&$assoc[key($assoc)]);
  }                                
  next($assoc);
}
($x=0;$x{ 如果($index[$x][“book”]==键($assoc)){ 编辑::修改(&$assoc[键($assoc)]); } 其次($assoc); } 如何
和$assoc[键($assoc)]