Solved

Two dimensional array problem

Posted on 2009-05-07
1
265 Views
Last Modified: 2012-05-06
Experts,

I'm trying to create a simple two dimensional array in PHP, following a guide pulled from the net.  My code is below.  I'm getting the usual undefined use of constant error, please help.
$pages = array( 
			   	array( Post => "homepage", Value => "homepage_page" ),
				array( Post => "contact", Value => "contact_page" ),
				array( Post => "status", Value => "status_page" ),
				);

Open in new window

0
Comment
Question by:nickmarshall
1 Comment
 
LVL 4

Accepted Solution

by:
bljak earned 500 total points
ID: 24324156
Where warning of course is true, neither Post nor Value are constants and can not be used without being quoted, take a look below for 2 possible solutions.
//first
$pages = array(
	array( "Post" => "homepage", "Value" => "homepage_page" ),
	array( "Post" => "contact", "Value" => "contact_page" ),
	array( "Post" => "status", "Value" => "status_page" ),
);
 
 
 
//second
define("Post", "Post");
define("Value", "Value");
 
$pages = array(
	array( Post => "homepage",Value => "homepage_page" ),
	array( Post => "contact", Value => "contact_page" ),
	array( Post => "status",  Value => "status_page" ),
);
var_dump($pages); 

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Number of reviews not counting correctly 2 22
mysql query for sum() 3 28
What if i make webbased alternative for MS Access 5 70
Reference key in foreach loop 4 21
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question