Error Message every time testing an array

  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

Hi,

Everytime I test arrays (am currently learning), I receive a message similar to the following, but my expected results are always correctly displayed underneath a bunch of these messages

Is this something to do with the level of warnings it gives the developer, for troubleshooting purposes etc...

Warning: Use of undefined constant name - assumed 'name' in E:\intranet\testing\php\7.2.php on line 11

Any advice would be appreciated

Many Thanks

Tommy A
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

undefined constant?

you have probably used name in the code somewhere, should it be "name" or (more likely) $name?

Post some code else we are just stabbing in the dark!
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

Sorry, should really have posted it first time round, here it is

<html>
<head>
<title> Listing 7.3 </title>
</head>
<body>

<?php

$characters = array (

array ( name=>"bob",
occupation=>"superhero",
age=>30,
speciality=>"x-ray vision" ),

array ( name=>"sally",
occupation=>"superhero",
age=>24,
speciality=>"superhuman strength" ),

array ( name=>"mary",
occupation=>"arch villain",
age=>63,
speciality=>"nanotechnology" )

);

foreach ( $characters as $val )

{

foreach ( $val as $key=>$final_val )

{

print "$key: $final_val<br>";

}

print "<br>";

}

?>

</body>
</html>
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

can i just add that that it seems to have removed a line break at the base of the code so please ignore what looks like an obvious error near the print statement
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

i think you need to use:

PHP Code: [ Select ]
 array ( 'name'=>"bob",
 
'occupation'=>"superhero",
 
'age'=>30,
 
'speciality'=>"x-ray vision" ),
  1.  array ( 'name'=>"bob",
  2.  
  3. 'occupation'=>"superhero",
  4.  
  5. 'age'=>30,
  6.  
  7. 'speciality'=>"x-ray vision" ),


It doesn't matter whether they are single or double quotes though.

PS, use the [code ] or [php ] BBtags when posting code - the mods get all upset otherwise :wink:
  • tommya
  • Graduate
  • Graduate
  • tommya
  • Posts: 221
  • Loc: United Kingdom

Post 3+ Months Ago

that worked a treat, thanks very much
it was just more annoying than a problem, just shows my learning material isnt upto scratch, but I'll soldier on

thanks again

Tommy
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

That was showing up as a warning... PHP knew what you meant, but was letting you know what you had wasn't perfect, which is why the array was working regardless.
.c

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.