dousuo8400 2014-02-19 15:11
浏览 52

从另一个多维数组中回显信息

How do i echo/print_r url arry code=>'LV_ARTICLES_ARTICLECODE' from the folowing code in another php file that is in the same dir?

function BuildSearchIndex($showHomePage = False,$functionLanguage) 
{
   $index_arr = array
   (
     array
     (
     'directory'=>'data/articles',//bestands locatie is data/articles/ "alles"
     'files_ext'=>array('xml'),//bestands extentie is "xml"
     'tags'=>array //alle tags zijn tussen de <> tekens
            (
            'LV_ARTICLES_DESCRIPTION' //artiekel omschrijvings tag

            /*,'LV_ARTICLES_DESCRIPTIONANDMEASURE',
            'LV_ARTICLES_SPECIFICATION'*/,

            'LV_ARTICLES_ARTICLECODE' //artiekel code / ID tag

            /*,'LV_ARTICLES_ARTICLECODE2',
            'LV_ARTICLES_SHORTMEMO',
            'LV_ARTICLES_LONGMEMO',
            'LV_ARTICLES_ARTICLECODE2'*/
            ),

     'url'=>array
            (
            'action'=>'article',

            /*'group_id'=>'content "/<LV_ARTICLES_GROUP>.*<LV_ARTICLES_ITEM>(.+)<\/LV_ARTICLES_ITEM>.*<\/LV_ARTICLES_GROUP>/isU"',*/

            'aid'=>'filename "/article_(\d+).xml/i"'
            ),

           'name'=>'LV_ARTICLES_DESCRIPTIONANDMEASURE',
           'code'=>'LV_ARTICLES_ARTICLECODE',
           'languages'=>array(),
           'additional'=>array
                (
                'price'=>'content "/<LV_ARTICLES_PRICE_EXVAT>(.+)<\/LV_ARTICLES_PRICE_EXVAT>/iU"',
                'vat'=>'content "/<LV_ARTICLES_VAT>(.+)<\/LV_ARTICLES_VAT>/iU"',
                'manufacturer'=>'content "/<LV_ARTICLES_MANUFACTURER>(.+)<\/LV_ARTICLES_MANUFACTURER>/iU"',
                'categories'=>'content "/<LV_ARTICLES_GROUP>(.+)<\/LV_ARTICLES_GROUP>/isU"'
                )

     ),

     array
     (
     'directory'=>'data/extrapages',
     'files_ext'=>array('xml'),
     'tags'=>array('LV_TITLE','LV_BODY'),
     'url'=>array(
     'action'=>'extra',
     'extra'=>'filename "/(.+).xml/i"'),
     'name'=>'LV_TITLE',
     'languages'=>array()
     )
   );
   $clear_arr = array
   (
     0=>array('dir'=>'./data/articles',
              'languages'=>array()),
     1=>array('dir'=>'./data/extrapages',
              'languages'=>array())
   );

   $lang=$functionLanguage->getLanguageList();
   foreach ($lang as $v) 
   {
     $index_arr[0]['languages'][$v['code']]='LV_ARTICLES_LANG_'.strtoupper($v['code']);
     $index_arr[1]['languages'][$v['code']]='LV_'.strtoupper($v['code']);
     $clear_arr[0]['languages'][$v['code']]=$v['code'];
     $clear_arr[1]['languages'][$v['code']]=$v['code'];
   }

   try 
   {
     $q=new Search();
     $q->clear_index($clear_arr);
     $q->make_index($index_arr);
   } 
   catch (Exception $e) 
   {
     echo $e->__toString();
   }

   if ($showHomePage) {
     header('location: index.php?action=home&lang='.strtoupper($functionLanguage->getCurrentLanguage()));
   }

}

I dont know why i have to add more detail. I really think my question is clear enough. But any way I tried $index_arr['']['url']['code'] first it might be wrong second its in a function. Can I even extract that info from there?

  • 写回答

1条回答 默认 最新

  • dongyao2001 2014-02-19 15:30
    关注

    You need to return $index_arr in the BuildSearchIndex function. Then when you call this function from the other file you could do this:

    $array = BuildSearchIndex($param1, $param2);
    echo $array[0]['url']['code'];
    

    The other way,if you can´t return the array on the function, would be pass the $index_arr by reference, doing something like this:

    function BuildSearchIndex($showHomePage = False,$functionLanguage, &$index_arr) 
    {
    $index_arr = array
       (
         array
         (....
    

    Then you call the function this way, and you will have access to the content you want:

    $array = array();    
    BuildSearchIndex($param1, $param2, $array);
    echo $array[0]['url']['code'];
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致