Solved

Two dimensional array problem

Posted on 2009-05-07
1
266 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

749 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