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

  • Home
  • SEARCH
  • 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 8200205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:21:41+00:00 2026-06-07T06:21:41+00:00

The code is: <?php $notes = array(Main/folder/02/12.jpg = twelve, Main/folder/02/16.jpg = sixteen ); $imglist

  • 0

The code is:

<?php
$notes = array("Main/folder/02/12.jpg = twelve",
               "Main/folder/02/16.jpg = sixteen"
               );
$imglist = array( "12.jpg",
                  "13.jpg",
                  "14.jpg",
                  "15.jpg",
                  "16.jpg"
                  );
for ($i=0;$i<(count($imglist));$i++){
    if(in_array($imglist[$i], $notes)){
        echo $imglist[$i];
        //Get key($notes) and //Cant figure out how to implement this key();
        echo $notes[$key];
    } //if ENDS
} //for ENDS
?>

What I need is that for $i=0 and $i=4, if() should return TRUE & do the echoes.

The pseudo-code/logic is:

  • Iterate through all the $imglist array one by one.
  • if the complete $imglist[$i] string is found anywhere in $notes array, get the key/index of that value in $notes, and echo $notes[$key] and $imglist[$i]. OR Echo $notes[$key].

For example the desired output of this for loop should be:

12.jpg Main/folder/02/12.jpg = twelve
16.jpg Main/folder/02/16.jpg = sixteen

The problem is that now this all code is just outputting none. Means that if condition is not returning TRUE ever. Whereas in theory it should return TRUE when $i is 0 & 4. Is my if() condition wrong? Is php not taking $imglist[$i] as a string? Should I use strpos?

  • 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-06-07T06:21:42+00:00Added an answer on June 7, 2026 at 6:21 am

    in_array() uses a loose comparison to search for elements and will not yield the results you’re looking for.

    Instead, you need to use your own logic (using strpos() as you guessed) to implement the functionality you desire, like so:

    foreach( $imglist as $image_key => $image)
        foreach( $notes as $notes_key => $note)
            if( !(strpos( $note, $image) === false))
                echo "$image $note\n";
    

    This will output:

    12.jpg Main/folder/02/12.jpg = twelve
    16.jpg Main/folder/02/16.jpg = sixteen
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

PHP code: echo date(c); //out put like this 2012-06-19T20:37:44+05:30 echo date(d M, Y); //out
I have the following PHP code: $data=mysql_query(SELECT * FROM notes WHERE rootNoteId='$noteId'); $mainArray; while($result
I've have the following (PHP) code that traverses an entire DOM document to get
Here's my php code <?php $pageOK = array('page0' => 'page0.php', 'page1' => 'content1.php', 'page2'
I want to add code php to variable with html, for example $html =
I just saw this code while studying the wordpress source code (PHP), You can
is there a possible bit of code (php, java, css, html) that will force
I need help to use jConfirm with this existing code (php & Jquery &
code: sql.php <?php $uid = trim($_POST['uid']); $pass= trim($_POST['pass']); $type= trim($_POST['type']); $link = mysql_connect(localhost,root,akash); if
Having php code: function getChildren($parent_id = 0) { .... return $SomeChildrenArray; } And Smarty

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.