如何在数组和数组中存储价值那么它在其他用途​​?

时间:2010-09-01 10:15:58

标签: php

我正在执行图像文件的搜索条件&使用print_r()它显示数组中图像路径的输出。现在我想存储这个阵列&对存储的数组中的特定图像路径执行搜索操作。 这是搜索图像文件的代码:

  

$ root1 = $ _SERVER ['DOCUMENT_ROOT'];

     

$ directory = $ root1。'/ Place4Info / Data / Admin_data /';

     

$ it = new   RecursiveIteratorIterator(new RecursiveDirectoryIterator($ directory));   $ I = 0;   $ NUM = 1;   while($ it-> valid()和$ iisDot()){           $ files = glob($ directory。$ it-> getSubPath()。'/ *。jpg');           的print_r($文件);

     

$ I ++;       }     $ IT->接着(); }

&安培;输出是:

  

数组([0] => C:/ Program   文件/的EasyPHP-5.3.2i / WWW / Place4Info /数据/ Admin_data /管理/ sports19.jpg   [1] => C:/程序   文件/的EasyPHP-5.3.2i / WWW / Place4Info /数据/ Admin_data /管理/ sports21.jpg   [2] => C:/程序   文件/的EasyPHP-5.3.2i / WWW / Place4Info /数据/ Admin_data /管理/ sports22.jpg   [3] => C:/程序   文件/的EasyPHP-5.3.2i / WWW / Place4Info /数据/ Admin_data /管理/ sports3.jpg   )

现在我希望将此输出存储在变量或数组中。 之后我想对该变量或数组执行搜索操作,比如查找"C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg "文件的路径。 &安培;存储导致变量。 我有一个代码,但我不知道如何应用它。

  

$ conditions = array(“Post.title<>”=>   $文件);           $这个 - >&后GT;找到( 'sports3.jpg',   array('conditions'=> $ conditions));         echo $ this;

但它给出了错误:

Fatal error: Using $this when not in object context in C:\Temp\test.php on line 17

1 个答案:

答案 0 :(得分:2)

你误解了PHP编程的基础知识,我的朋友。您的问题不是关于如何使用数组,而是如何避免编程中的逻辑错误。看到我的回答。

$这是一个魔术变量,它总是代表一个经过证实的类的实际实例指针。例如。它使没有感觉在非静态类上下文之外使用它,这就是你正在做的事情。

找出哪个类具有正确的Post对象并正确使用其API。

e.g。

$post = new Post;
$post->find('sports3.jpg', array('conditions' => $conditions));