Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6536465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:29:48+00:00 2026-05-25T10:29:48+00:00

The issue here is that when I do print_r after I create the array

  • 0

The issue here is that when I do print_r after I create the array with $picnameoutput it prints the array as you will see in the screenshot.

Later after I run the for loop and echo it just to see the output it only gives me 1 value and I can’t figure out why it picks that value, it is not even the first one in the array.

Very Frustrated.

Here is my code

<?php
  $largedir = 'images/headshots/large';
  $large = scandir($largedir);

  $picnameoutput = preg_grep("/adam.*/", $large); 
  print_r($picnameoutput);

  for ($i=0; $i<count($picnameoutput); $i++); {
  echo "$picnameoutput[$i]";
  }
?>

And here is a screenshot so you can see what I mean

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:29:48+00:00Added an answer on May 25, 2026 at 10:29 am

    You have a semicolon ; after for() before bracket. Remove it.

    So

    for ($i=0; $i<count($picnameoutput); $i++); {
    echo "$picnameoutput[$i]";
    }
    

    becomes

    for ($i=0; $i<count($picnameoutput); $i++) {
        echo "$picnameoutput[$i]";
    }
    

    however I would recommend to use foreach() instead

    foreach ($picnameoutput as $pic) {
        echo $pic;
    }
    

    which is pretty easy to use and even faster than your for loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
Sample: I've created a minimal set of files that highlight the issue here: http://uploads.omega.org.uk/Foo3.zip
I'm seeing basically the same issue described here I have a table that starts
Here's the issue: I have 2 data contexts that I would like to do
Here is the issue I am having: I have a large query that needs
Here I am faced with an issue that I believe(or at least hope) was
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
Here's the issue: I have a list of App names that I want to
So here's my issue. I have an image that I need to shrink. The
Here's my issue, I'd like to mock a class that creates a thread at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.