470,855 Members | 1,318 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Can I get the value from an assoc array that is returned by a function...in one statement?

I want to be able to get the present year in one statement. I know that I
can do it this way:

$y = getdate();
echo 'year='.$y['year'];

But, I want to do something like:

echo 'year='.getdate()['year']; # BAD, I know

Ideas?

TIA,

Larry Woods
Jan 12 '06 #1
6 1263
lwoods wrote:
I want to be able to get the present year in one statement.


http://php.net/date

--
E. Dronkert
Jan 12 '06 #2
NC
lwoods wrote:

I want to be able to get the present year in one statement. I know that I
can do it this way:

$y = getdate();
echo 'year='.$y['year'];

But, I want to do something like:

echo 'year='.getdate()['year']; # BAD, I know


There's no need to use getdate() if all you want is year. Consider
this:

echo date('Y');

Cheers,
NC

Jan 12 '06 #3
lwoods wrote:
I want to be able to get the present year in one statement. I know that I
can do it this way:

$y = getdate();
echo 'year='.$y['year'];

But, I want to do something like:

echo 'year='.getdate()['year']; # BAD, I know

Ideas?


echo 'year=', date('Y');
If your problem is what you used for the subject
Can I get the value from an assoc array that is returned by a
function...in one statement?
then there's a lovely solution proposed by ... searching ...
.... Robin Goodall on a similar problem I posted a long way back.

<http://groups.google.com/group/comp.lang.php/browse_thread/thread/96568bc7c66ad4a/ce59a0c7758992b9>
which I shortened to <http://shorterlink.com/?S9KW1T>

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jan 12 '06 #4
Thanks, all....

I'll follow up on the Goodall solution, Pedro.

Larry

"Pedro Graca" <he****@dodgeit.com> wrote in message
news:sl*******************@ID-203069.user.individual.net...
lwoods wrote:
I want to be able to get the present year in one statement. I know that
I
can do it this way:

$y = getdate();
echo 'year='.$y['year'];

But, I want to do something like:

echo 'year='.getdate()['year']; # BAD, I know

Ideas?


echo 'year=', date('Y');
If your problem is what you used for the subject
Can I get the value from an assoc array that is returned by a
function...in one statement?
then there's a lovely solution proposed by ... searching ...
... Robin Goodall on a similar problem I posted a long way back.

<http://groups.google.com/group/comp.lang.php/browse_thread/thread/96568bc7c66ad4a/ce59a0c7758992b9>
which I shortened to <http://shorterlink.com/?S9KW1T>

--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!

Jan 12 '06 #5
Thanks

Larry

"Ewoud Dronkert" <fi*******@lastname.net.invalid> wrote in message
news:m3********************************@4ax.com...
lwoods wrote:
I want to be able to get the present year in one statement.


http://php.net/date

--
E. Dronkert

Jan 12 '06 #6
Thanks

Larry
"NC" <nc@iname.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
lwoods wrote:

I want to be able to get the present year in one statement. I know that
I
can do it this way:

$y = getdate();
echo 'year='.$y['year'];

But, I want to do something like:

echo 'year='.getdate()['year']; # BAD, I know


There's no need to use getdate() if all you want is year. Consider
this:

echo date('Y');

Cheers,
NC

Jan 12 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Jim SUTTON | last post: by
5 posts views Thread by Andrew Poulos | last post: by
9 posts views Thread by ckerns | last post: by
7 posts views Thread by The87Boy | last post: by
7 posts views Thread by Terry Olsen | last post: by
5 posts views Thread by KDawg44 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.