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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:08:15+00:00 2026-05-16T15:08:15+00:00

I have a PHP function that returns an array. This is the output of

  • 0

I have a PHP function that returns an array. This is the output of print_r($myArray):

Array ( 
[id] => 8166 
[customer_id] => 73 
[nickname] => AnnieB 
[name] => Anastasia Beaverhausen 
[email] => annieb@annieb.com 
[phone] => 555-555-5555 
[company] => Annie B's 
[address1] => 123 Main Street 
[address2] => Apartment 555 
[city] => Chicago 
[state] => IL 
[zip] => 55555 
[billing] => 1 
[residence] => 0 
[token] => 
[verified] => 1 ) 

I should be able to access any of the members by saying something like $myArray['city'], correct? I know I’ve done this in the past, but it keeps returning an empty string, even when there is a value in the city field.

Any ideas?
==================MORE CODE POSTED PER REQUESTS=============================
I’m using this in Joomla, so there are a few lines that are specific to Joomla. The end purpose of this code is to populate a dropdown list with addresses from a database; the option values contain an imploded string of all column values (to be accessed via javascript later) and the option text is a single field. Here’s the code that creates the dropdown:

 foreach (getAddresses($AcctID) as $id => $info) {
                print_r($info);
                $nickName = $info[2];
                error_log("nickname=".$nickName);
                $infoStr = implode("|", $info);
                $addressOptions .= "<option value=\"{$infoStr}\">$nickName</option>";
     }

The getAddresses function is here (this is working correctly):

function getAddresses($AcctID) {
    $db =& JFactory::getDBO();
    $query = "select * from jos_customers_addresses where customer_id = ".$db->quote($AcctID);
    $db->setQuery($query);
    if (!$db->query()) error_log($db->stderr());

    if (!$db->getNumRows()) 
        return false;
    else
        return $db->loadAssocList();
}

The print_r($info) line is what is returning the array I originally posted. The next two lines are the ones giving me problems:

$nickName = $info[2];
error_log("nickname=".$nickName);

I’ve also tried $nickName = $info[‘nickname’] and gotten the same result – no value, even though there’s obviously a value in the print_r, and the value does come through correctly in the code generated by the implode line. If you can find someplace between those two lines where I’m overwriting my variable, or whatever, please point it out to me, because I’m clueless as to why I can’t get a handle on this value.

  • 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-16T15:08:15+00:00Added an answer on May 16, 2026 at 3:08 pm

    I should be able to access any of the
    members by saying something like
    $myArray[‘city’], correct?

    Yes, that’s correct.

    I know I’ve done this in the past, but
    it keeps returning an empty string,
    even when there is a value in the city
    field.

    If nothing is showing up, there’s probably not a value there, which as the comments said, is most likely a bug in your code (something overwriting that key). To be sure there’s nothing there, instead of echo $myArray['city'] try var_dump($myArray['city']) — this will tell you if it’s an empty string (string(0) "") or not set at all (NULL)

    Take your print_r($myArray) and put it immediately before the statement where you use $myArray['city']. is the ‘city’ key still set? If so, double check to make sure you don’t have a typo… capitalization matters! If it’s not still set, move the print_r($myArray) up a few lines and repeat until you find what’s unsetting $myArray['city']

    …Or just post more code ;-)

    EDIT: Did $info[2] need to be $info['city']?

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

Sidebar

Related Questions

PHP: I have made up a function that returns an array. I would like
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a PHP function that builds a JSON array via $jsonArray= array(); for
I'm trying to build a PHP function that allows me to have an array
I have a php code that gives me the following output: (its an array)
I have a PHP function that extract dat of an invoice from DB. The
I have a PHP function that takes a variable number of arguments (using func_num_args()
I have a PHP function that requires can take 3 parameteres... I want to
I have a PHP function that I want to make available publically on the
Is it possible to have a PHP function that is both recursive and anonymous?

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.