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 6875501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:19:58+00:00 2026-05-27T04:19:58+00:00

I have an array $test = array(‘one’, ‘two’, ‘three’, ‘four’, ‘five’); I unset two

  • 0

I have an array

$test = array('one', 'two', 'three', 'four', 'five');

I unset two and four (because I really really dislike even numbers)

unset($test[array_search('two', $test)]);
unset($test[array_search('four', $test)]);

And am left with an array

$test = array(
[0] => 'one',
[2] => 'three',
[4] => 'five'
);

Now I need to loop through that array and obtain the value along with the correct key. I want to display

0 = one
2 = three
4 = five

What should I use to achieve that? I tried using standard

for($i=0; $i<count($test); $i++)

but that is not effective because it will loop and give me 0 1 2 instead of 0 2 4.
Any suggestions?

  • 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-27T04:19:59+00:00Added an answer on May 27, 2026 at 4:19 am

    You can use a foreach loop for this

    foreach($test as $key => $value) {
    echo "$key = $value";
    }
    

    Read about foreach loop at at php.net manual

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

Sidebar

Related Questions

I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an array that looks like: $fields = array( f1 => array(test), f2
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have an array: int test[]={10212,10202,11000,11000,11010}; I want to split the inetger values to
If i have an array of strings for example Static final String[] TEST =
I have an array of strings like this: test[1] = AA; test[2] = BB;
I have an array: Array ( [0] => ololo [2] => test [3] =>
I have an array (below) var img_name = new Array(images/test.jpg, images/test.jpg); var imgTotal =
I have this array $arr = array('test1', 'test', 'test3', 'var1', 'var5', 'var'); and I
I have test array of hex(radix 16) numbers var numbers = [01,02,a1]; and I

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.