Jump to content

Newbie Array Question...


strongbad

Recommended Posts

I am fairly new to PHP, coming over from JAVA.

 

In JAVA, you can select an element of an array and set it as a separate variable, such as:

 

String name="":

name = array[4];

 

But in PHP I am trying this:

 

$ban = $banners[$selected_banner];

 

Where $selected_banner is a random number.

 

Unfortunately, I am gettting the following error...

 

Catchable fatal error: Object of class stdClass could not be converted to string

 

Are arrays in PHP able to be used in such a way?

 

What am I missing?

 

Link to comment
https://forums.phpfreaks.com/topic/232000-newbie-array-question/
Share on other sites

Simple answer = yes.

ie...

<?PHP
$myarray = array("red", "white", "blue");
$some_number = 2;
$color = $myarray[$some_number];
echo $color; /* would show blue */
?>

 

This is pretty much what I have going on.  If I use:

 

echo $banners[$selected_banner];

 

It prints out the propper URL.

 

But if I try to assign it, it throws that error.  Is the problem because it's a URL?

 

What am I missing here?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.