473,626 Members | 3,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1345
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.c om/group/comp.lang.php/browse_thread/thread/96568bc7c66ad4a/ce59a0c7758992b 9>
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.ind ividual.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.c om/group/comp.lang.php/browse_thread/thread/96568bc7c66ad4a/ce59a0c7758992b 9>
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*******@last name.net.invali d> wrote in message
news:m3******** *************** *********@4ax.c om...
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.goo glegroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2534
by: Stefan Richter | last post by:
Hi, I want to create an associative Array with a PHP variable (article ID) as Key and another associative array as it's value. How do I instanciate it, how can I fill it? I want something like this:
6
21040
by: Jim SUTTON | last post by:
I am sure I have had this problem before and can't remember what the fix is... The documentation says that an array can be returned from a function provided you do the following:- 1. Declare the function with an explicit return type - the examples suggest it also needs the parentheses to denote a returned array thus: Private Function GetResultArray(RawResults as String, RequiredResultSetName
15
3218
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone tell me why these DIVs don't drift to the left as they are supposed to? <script language="javascript">
5
2928
by: Andrew Poulos | last post by:
If I'm searching for an occurance of a value in a multi-dimensional array how can I get it's index returned as an array, if found? For example, if: foo = new Array(); foo = , 5, , 9, 10]; Array.prototype.findValue = function(val) { // blah }
9
2923
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval ("document.forms."+rowString+".value")) == true ) { //this alert works if the value is a letter,i.e,"a" alert("You have entered an non-numeric value.\nEnter a number in the appropriate box.");
7
2394
by: The87Boy | last post by:
Is there any ways to make a function like system(), which returns more than one value (true or false) and (the array)
7
10311
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If lvServers.InvokeRequired = True Then lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
5
5377
by: KDawg44 | last post by:
Hi, Is there a way to get a multidimensional associative array with the entire result set? I would like to get a an array like this: resultsArray How can I accomplish this? Can I do something like this? var $userArray = array(array());
5
2674
by: ctj951 | last post by:
I have a very specific question about a language issue that I was hoping to get an answer to. If you allocate a structure that contains an array as a local variable inside a function and return that structure, is this valid? As shown in the code below I am allocating the structure in the function and then returning the structure. I know if the structure contained only simple types (int, float) this will work without problems as you...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1511
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.