PHP Coding

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

newonline
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jul 17, 2013 2:46 pm

PHP Coding

Postby newonline » Thu Jul 18, 2013 12:48 am

Hi

I am pretty new to php codeing and I need some ons help for the following code.
When I use the code, the outout look like this

"John","last_name"=>"Smith"); ?>



And the code looks like this

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/tr/jtml4/loose.dtd">


<html lang="en">
<head>
<title>Associative Arrays </title>
</head>
<body>


<?php $assoc=array("first_name"=>"John","last_name"=>"Smith"); ?>
<?php echo $assoc["first_name"]; ?><br />
<?php echo $assoc["first_name"]."".$assoc["last_name"]; ?><br />



</body>
</html>


Any ideas where am i going wrong???

pbs
New php-forum User
New php-forum User
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India
Contact:

Re: PHP Coding

Postby pbs » Thu Jul 18, 2013 1:43 am

there is no problem in the code, how are you calling this page?

peterzwijnenberg
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jul 18, 2013 2:31 am
Contact:

Re: PHP Coding

Postby peterzwijnenberg » Thu Jul 18, 2013 2:39 am

You could try to set John and Smith between single quotes ( 'John' and 'Smith' )
the echo's are good, but there is something wrong in your assoc

johnj
php-forum Super User
php-forum Super User
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP Coding

Postby johnj » Thu Jul 18, 2013 8:45 pm

I don't see anything wrong with the code. The output looks ok to me.

cappy2354
New php-forum User
New php-forum User
Posts: 5
Joined: Fri Jul 19, 2013 11:07 am

Re: PHP Coding

Postby cappy2354 » Wed Sep 11, 2013 10:08 am

Change your code to this and call it a PHP page instead of a HTML..

Code: Select all

<!DOCTYPE HTML>
<html>
<head>
<title>Associative Arrays</title>
</head>
<body>
<?php
$assoc = array("first_name"=>John","last_name"=>"Smith");
echo $assoc["first_name"] . "<br />";
echo $assoc["first_name"]."&nbsp;".$assoc["last_name"] . "<br />";
?>
</body>
</html>


The code above with read on a page like this:
John
John Smith


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 4 guests