Php 获取数组中数组的值

Php 获取数组中数组的值,php,Php,在这件事上不确定,希望你能在这件事上帮我 这是我的密码 Loader::library('file/types'); $ih = Loader::helper('image'); $names = explode("||",$this->tName); $urls = explode("||",$this->tUrl); $fIDs = explode("||",$this->fID); Loader::model('file');

在这件事上不确定,希望你能在这件事上帮我

这是我的密码

Loader::library('file/types');
    $ih = Loader::helper('image');
    $names = explode("||",$this->tName);
    $urls = explode("||",$this->tUrl);
    $fIDs = explode("||",$this->fID);

    Loader::model('file');
    $i = Loader::helper('image');

    $v = array();
    $cc = 0;

    foreach ($names as $k=>$n){
      if (intval($fIDs[$k]) > 0 ) :
        $img = $test = File::getByID($fIDs[$k]);
        $fv = $img->getExtension();
        $ft = FileTypeList::getType($fv);
        $img = $ft->type == 1 ?  $img : false;  
      else :
        $img = false;
      endif;
    $v[$cc]['name']         = $n;
    $v[$cc]['url']          = $urls;
    $v[$cc]['src']          = $img ? $ih->getThumbnail($img,100,100)->src : false;
    $cc ++;
    }
    return $v;
我遇到的问题是从代码中的$URL获取数组值。(倒数第五名)


谢谢你的帮助。非常感谢。

我认为你必须这样做:

$i = 0;

foreach ($names as $k=>$n){
  if (intval($fIDs[$k]) > 0 ) :
    $img = $test = File::getByID($fIDs[$k]);
    $fv = $img->getExtension();
    $ft = FileTypeList::getType($fv);
    $img = $ft->type == 1 ?  $img : false;  
  else :
    $img = false;
  endif;
$v[$cc]['name']         = $n;
$v[$cc]['url']          = $urls[$i]; //changed
$v[$cc]['src']          = $img ? $ih->getThumbnail($img,100,100)->src : false;
$cc ++;
$i++; //changed
}
return $v;

由于使用$k作为索引在names数组中循环,因此可以使用相同的索引访问匹配的url。因此,您可以将该行更改为:

$v[$k]['url'] = $urls[$k];
不需要使用$cc变量跟踪索引,因为$k已经表示names数组中的当前索引。您已经以相同的方式访问fIDs阵列(使用$k)

$v[$k]['url'] = $urls[$k];