Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    265
    Thanks
    49
    Thanked 1 Time in 1 Post

    referencing 2 dimensional array

    I have the following code:

    Code:
    $backgrounds = array (
    	    array ("http://www.doig.com.au/wp-content/themes/doig/bg/Fremantle.jpg","<a href='http://nicholasjv.blogspot.com.au/2012/08/postcard-from-fremantle.html' rel='nofollow'>Nicholas V</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/fremantle.jpg","<a href='http://www.heifetzphotography.com.au/' rel='nofollow'>Jay Heifetz Photography</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/Fremantle2.jpg","<a href='http://www.ytravelblog.com/fremantle-australia/' rel='nofollow'>Craig Makepeace</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/Port-of-Fremantle.jpg","<a href='#' rel='nofollow'>Unknown</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/fremantleC-post-office-2007.jpg","<a href='http://www.mingor.net/localities/fremantle-central.htm' rel='nofollow'>Mingor.net</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/Status-of-Bon-Scott-AC-DC-Fremantle-WA-Australia.jpg","<a href='http://www.travelwalls.net/australia/bon-scott-fremantle-attractions-western-australia-australia/' rel='nofollow'>Travel Wallpapers</a>"),
    		array ("http://www.doig.com.au/wp-content/themes/doig/bg/sunset.jpg","<a href='http://steve.doig.com.au'>Steve Doig</a>"));
    
    shuffle($backgrounds);


    I can reference the background image successfully:

    Code:
    <style>	
    	  html {
            background: url(<?php echo $backgrounds[0][0]; ?>) no-repeat center center fixed; 		
    		-webkit-background-size: cover;		
    		-moz-background-size: cover;		
    		-o-background-size: cover;		
    		background-size: cover;	}
    	</style>
    However, I can't get the 2nd value to be output:

    Code:
    <p>Photo &copy; copyright <?php echo $background[0][1]; ?></p>
    Live example

    Why won't [0][1] be output?
    Last edited by SRD75; 05-27-2013 at 03:11 AM.

  • #2
    New Coder
    Join Date
    May 2005
    Location
    New Zealand
    Posts
    76
    Thanks
    0
    Thanked 6 Times in 6 Posts

    The variable name is misspelled

    Hi,

    Where you are doing
    PHP Code:
    <p>Photo &copy; copyright <?php echo $background[0][1]; ?></p>
    the name of the background variable is mispelled, should be $backgrounds.

    Cheers,
    DouG.

  • Users who have thanked DougMck for this post:

    SRD75 (05-27-2013)

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    265
    Thanks
    49
    Thanked 1 Time in 1 Post
    Fantastic. Thanks Doug.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •