Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Two dimensional array problem

Posted on 2009-05-07
1
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 4

Accepted Solution

by:
bljak earned 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

610 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