开发者

how to store value in array & then it use in other?

开发者 https://www.devze.com 2023-01-13 19:37 出处:网络
i am performing search condition of image file & using print_r() it shows output of image path in array. now i want to store this array & perform search operation for particular image path in

i am performing search condition of image file & using print_r() it shows output of image path in array. now i want to store this array & perform search operation for particular image path in that stored array. this is code of searching image file:

$root1 = $_SERVER['DOCUMENT_ROOT'];

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

$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); $i=0; $num=1; while($it->valid() and $iisDot()) { $files = glob($directory.$it->getSubPath().'/*.jpg'); print_r($files);

$i++; } $it->next(); }

& output is:

Array ( [0] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports19.jpg [1] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports21.jpg [2] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg [3] => C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports3.jpg )

now i want store this output in a variable or in array. after that i want to perform search action on that variable or array, like find the path of "C:/Program Files/EasyPHP-5.3.2i/www/Place4Info/Data/Admin_data/admin/sports22.jpg " file. & store that result in variable. i got one code but i dont know how to 开发者_如何转开发apply this.

$conditions = array("Post.title<>" => $files); $this->Post->find('sports3.jpg', array('conditions' => $conditions)); echo $this;

but it give error:

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


You're misunderstanding the basics of PHP programming, my friend. Your question is not about how to use arrays but how to avoid a logic error in your programming. See my answer.

$this is a magic variable that always represents the actual instance pointer of a substantiated class. E.g. it makes no sense to use it outside of a non-static class context, which is what you're doing.

Figure out which class has the correct Post object and use its API appropriately.

e.g.

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号