About the PHP loop output problem, ask the heroes to help!

Source: Internet
Author: User
Little brother in WordPress wrote a program, the approximate process is as follows:

1, $get _posts_array call a category of articles

$get _posts_array = query_posts (Array (' posts_per_page ' = = $numberposts, ' by ' = ' = ' $orderby ', ' category__and ' = >array ($sub _cat_id_str)));


2. Loop to find all the pictures in the article

foreach ($posts _array as $index = + $post _value_array) {if ($post _value_array->post_status = = ' publish ') {Ob_start ( );      Ob_end_clean ();p reg_match_all ('//i ', $post _value_array->post_content, $pic _rexz); $post _item_array= $post _value _array->id. ' # '. $post _value_array->post_title. ' # '. $post _value_array->post_name. ' html# '. $post _value_array->guid. ' # '; if (!empty ($pic _rexz[1]) {$posts _pic_array[$index] = Array_merge ($pic _rexz[1], (array) $post _item_array);}}}


3. When using a foreach or if statement to output an array $posts_pic_array, the problem occurs as follows:

1, in the XAMPP environment of this machine, output array with foreach or if statement $posts _pic_array are normal;

2, uploaded to the server windows on IIS + PHP5.4 environment, in the article classification id=1, the loop output $posts _pic_array array, can only print 3 data. (The Ps:count ($posts _pic_array) array is 150 records). Why other classifications are normal, other categories of $posts_pic_array Records also have 50-100 different Ah! Either the foreach or if statements have been tested, and only 3 records can be output.

Commissioning for 2 days, I hope you can help!


Reply to discussion (solution)

On-line reply, solve!

if ($post _value_array->post_status = = ' publish ')

Is that the decision to filter out?

if ($post _value_array->post_status = = ' publish ')

Is that the decision to filter out?

Tested, not related to this, when the classification of id=1, COUNT ($posts _pic_array) Statistics There are 150, with the print command can also print the array, but with a foreach or for loop, can only loop out 3, And, oddly enough, the statement after the foreach statement is not executed. is not a memory overflow and other problems Ah!

Problem, find it! Really is a memory overflow problem, a unset statement actually can let 128M of php.ini configuration overflow! Just tested, delete the unset statement is normal!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.