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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:07:35+00:00 2026-06-11T06:07:35+00:00

i have the below php search script that will traverse a multidimentional array. when

  • 0

i have the below php search script that will traverse a multidimentional array. when $value is found it will return it, but i wish to return the address as well (considering it is only 2 levels)

function arr_search($array, $line, $lvl=0)
{ 



// Loops through each element. If element again is array, function is recalled. If not, result is echoed.
foreach($array as $key=>$value)
{ 
    if(is_array($value))
    {
        arr_search($value, $line); 
    }else{ 
          if(strpos($line, $value))
          echo "found $key: $value\n";
          // return $value; // should return array with [?],[$key],[$value]
    }

}

return false;
}

you can notice that $key is the address of the latest array found. but i want to have the index of the parent array.

array example:

Array
(
[0] => Array
    (
        [0] => string324
        [1] => string234
        [2] => string7567
        [3] => stringw34

    )

[1] => Array
    (
        [0] => string4563
        [1] => string37

    )

[2] => Array
    (
        [0] => string3735
        [1] => string3563
        [2] => string3563
        [3] => string356
        [4] => string356
    )
)
  • 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-11T06:07:36+00:00Added an answer on June 11, 2026 at 6:07 am

    This should help you.

    <?php
    
    function array_find_deep(array $array, $string, array &$result) {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $success = array_find_deep($value, $string, $result);
                if ($success) {
                    array_unshift($result, $key);
                    return true;
                }
            } else {
                if (strcmp($string, $value) == 0) {
                    array_unshift($result, $key);
                    return true;
                }
            }
        }
        return false;
    }
    
    $array = array(
        1 => array(
            1 => array(
                1 => "a",
                2 => "b",
                3 => "c",
                4 => "d",
                5 => "e",
            ),
            2 => array(
                1 => "f",
                2 => "g",
                3 => "h",
                4 => "i",
                5 => "j",
            ),
            3 => array(
                1 => "k",
                2 => "l",
                3 => "m",
                4 => "n",
                5 => "o",
            ),
        ),
        2 => array(
            1 => array(
                1 => "A",
                2 => "B",
                3 => "C",
                4 => "D",
                5 => "E",
            ),
            2 => array(
                1 => "F",
                2 => "G",
                3 => "H",
                4 => "I",
                5 => "J",
            ),
            3 => array(
                1 => "K",
                2 => "L",
                3 => "M",
                4 => "N",
                5 => "O",
            ),
        ),
        3 => array(
            1 => array(
                1 => "p",
                2 => "q",
                3 => "r",
                4 => "s",
                5 => "t",
            ),
            2 => array(
                1 => "u",
                2 => "v",
                3 => "w",
                4 => "x",
                5 => "y",
            ),
            3 => array(
                1 => "z",
                2 => "P",
                3 => "Q",
                4 => "R",
                5 => "S",
            ),
        ),
    );
    
    $result = array();
    $success = array_find_deep($array, 's', $result);
    
    var_dump($result);
    

    Will display the “way” to get to your data.

    array(3) {
      [0]=>
      int(3)
      [1]=>
      int(1)
      [2]=>
      int(4)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've search for the issue, but cant find it, I have a script that
I have an Array like below in PHP array( (int) 0 => array( 'id'
I have a small script which im using to test PHP mail(), as below:
Tech used: PHP 5.3.10 Hi, I have an array (example below) I need to
I have developed a script that uses php's imap_search and when it gets to
I have a php script that uses curl to get the contents of a
I have a jquery.ajax routine that calls a php script. The php script does
I have se the below date format in the codeignitor config.php $config['log_date_format'] = 'd/m/Y';
Below is an old PHP function I have for a dropdown list for users
I have a basic PHP question, take the code below for example, let's say

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.