/    Sign up×
Community /Pin to ProfileBookmark

I am new to PHP and was wondering what I’m doing wrong. I set a variable to “05568” and the output is “366” What am I doing wrong?

[CODE]
<?php
$name = ‘Jonh Rivers’;
//echo $name;
$address = “</br>” . ‘33417 Jones st.’;
//echo “</br>” . $address;
$city = “</br>” . ‘Johnson’;
$state = ‘ UT ‘;
$zipC = 05568;
$message = $name . $address . $city . $state . $zipC;
//$message .= $address;
echo $message;
?>
[/CODE]

This is what it outputs:

Jonh Rivers
33417 Jones st.
Johnson UT 366

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJun 04.2015 — A zip code needs to be a string not a number value. By doing what you did you would never see the leading 0 in your output since it would be stored as merely 5568. As to why it comes out 366, I don't know.

$zipC = '05568';
Copy linkTweet thisAlerts:
@NogDogJun 05.2015 — An unquoted number with a leading zero will be read as an octal number. Since 8 is not a valid digit in base 8 (0-7 are), it ignores the 8, and 0556 in octal converts to 366 in decimal, and since the octal value was stored as an integer, when PHP casts it to a string during the echo, it assumes a decimal representation.
×

Success!

Help @madhatter40 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...