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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:13:35+00:00 2026-05-27T21:13:35+00:00

I need helps on the PhP array method deployed below: Actual PhP code: $itemsB

  • 0

I need helps on the PhP array method deployed below:

Actual PhP code:

$itemsB = array("Steve Jobs"=>"USA", "Thomas Edison"=>"USA");
echo $itemsB['Steve Jobs'];
echo '<br />';
echo $itemsB['Thomas Edison'];

Expected Result:
USA
USA


Created DIY method below base on the above and hope to retrieve the same result but failed (getting no output)? The reason I am using this DIY method due to I have a list of Profile Data that need to fill into the conventional array method of : $items = array(‘name1’=>’value1’, ‘name2’=>’value2’);

$ProfileName[0] = "\"Steve Jobs\"=>\"USA\"";
 $ProfileName[1] = "\"Thomas Edison\"=>\"USA\"";

 $items = array("$ProfileName[0]", "$ProfileName[1]");
 echo $items['Steve Jobs'];
 echo '<br />';
 echo $items['Thomas Edison'];

Please advice!
Cheers


Alright, brief updates on what I am looking for if you still find unclear on the above. Below is the code to search Profile Name for autocomplete method on text field box. The code below is working if I entered the static values into the array. But, I have a list of Profile Names in the Database that I wanted to populate and add it into the array below. Thus, I thought of do some DIY that shown above. Unless there is other solution for this. Please advice

$q = strtolower($_GET["q"]);
if (!$q) return;

$items = array("Steve Jobs"=>"USA", "Thomas Edison"=>"USA");

foreach ($items as $key=>$value) {
    if (strpos(strtolower($key), $q) !== false) {
        echo "$key|$value\n";
    }//END IF
}//END FOR
  • 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-27T21:13:35+00:00Added an answer on May 27, 2026 at 9:13 pm

    This should work for you, if I’m understanding your question correctly:

     $ProfileName[0] = 'Steve Jobs|USA';
     $ProfileName[1] = 'Thomas Edison|USA';
    
     $items = array();
    
     foreach($ProfileName as $p){
        $items[substr($p,0,strpos($p,'|'))] = substr($p,strpos($p,'|')+1,strlen($p));
     }
    
      print_r($items);
     echo $items['Steve Jobs'];
     echo '<br />';
     echo $items['Thomas Edison'];
    

    This seems like a long way around to get to the same place, but you could try something like this.

    Or something like this could help if you’re pulling stuff from the database:

    $db = new mysqli('host','user','password','db-name');
    
    if ($result = $db->query("SELECT name,location FROM `table`"))
        {
            if ($result->num_rows > 0)
            {
                while ($row = $result->fetch_object())
                {
                    $items[$row->name] = $row->location;
                }
            }
        }
     echo $items['Steve Jobs'];
     echo '<br />';
     echo $items['Thomas Edison'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help to use jConfirm with this existing code (php & Jquery &
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need some help with sorting a multidimensional array in php. I need the
I need your help., How to pass the array values in query string... <?php
Need help with PHP Mysql code to insert multiple select data into database. With
I need to use Zend Captcha and wrote the follwoing code: <?php require_once ('Zend/Form.php');
I need help rewriting online.php to -> /users/online and profile.php?id=3426 to -> /users/3426 and
I need help finishing this statement. It is frustrating that two of the PHP
I am newbee with PHP and MySQL and need help... I have two tables
Hey, I need help isolating part of a url in PHP. say I have

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.