LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-27-2004, 10:06 AM   #1
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Rep: Reputation: 31
PHP: accessing unnamed array


Code:
$temp = array_splice( $data, $index, 1 );
$update_array[] = $temp[0];
I would like to be able to access the '0' index of the array being returned by array_splice without having to use the temporary variable. I would like something like this:

Code:
$update_array[] = ${array_splice( $data, $index, 1 )}[0];
This is obviously not the right code, but I hope you get the drift of what I am trying to do. Thanks for any help you may be able to provide.
 
Old 04-27-2004, 10:21 AM   #2
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
You kinda lost me, I hardly ever use arrays so I don't know everything they're capable of. I was just wondering why you are using array_splice and update_array in your code. I'm not sure what those functions do exactly.

Just curious, why can't you just use the standard array format:

Code:
<?php 

$temp = array('$date', '$index', '1');

?>
Like I said I'm not too familiar with arrays so if you could let me know those other functions do I'd appreciate it.
 
Old 04-27-2004, 10:40 AM   #3
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by msound

Like I said I'm not too familiar with arrays so if you could let me know those other functions do I'd appreciate it.
Just an etiquette note, you normally don't reply to someones thread with questions like you asked. If you have questions about these functions specifically, it would be more appropriate to start your own thread and reference my post.

In addition, www.php.net has a wonderful site that documents the language very well.

http://www.php.net/array
http://www.php.net/array_splice

In addition, you can look up any php function by adding its name to the end of the URL: http://www.php.net, like I did above.
 
Old 04-27-2004, 12:00 PM   #4
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
Hmmm, I thought this was a discussion board, where people came to discuss things. You posted becuase you have a question and you needed someone else's help. But when someone asks YOU for help, you throw this etiquette BS in their face.

Its people like you who bring great online communities like this down. If you aren't willing to share your knowledge with other people, then I hope people refuse to share their knowledge with you. After all, I have a feeling your question could've been answered with a few google searches as well.

What search engines like google lack however is personalization. Discussoin Boards are great becuase in most cases, you can get a good answer for your specific question. Then you can reply with either a thank you, or a follow up question.

But then there are those cases where the person who responds is a big Douche bag. I nomintate mrtwice for the Biggest Douche in the Universe award!
 
Old 04-27-2004, 01:40 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 21,610
Blog Entries: 47

Rep: Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413Reputation: 1413
Cummon, both of you, cut it out, OK?


Usually it isn't people that disappoint you, but your own expectations.
 
Old 04-27-2004, 02:03 PM   #6
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
Yeah i think i over reacted just a little. I just come to these forums in the hopes of learning new things and helping other people. When someone gives me a crash course on proper discussion board etiquette I get a little annoyed. I understand how frustrating it can be to have someone hijack your thread but I didn't think my question strayed off topic. Sorry about the whole douche bag thing but that was actually out of an episode of southpark, gotta love southpark...
 
Old 04-27-2004, 02:36 PM   #7
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,755

Rep: Reputation: 88
Do you not want the temp, or two statements?
Code:
array_splice( $data, $index, 1 );
$update_array[] = $data[0];
 
Old 04-27-2004, 04:28 PM   #8
mrtwice
Member
 
Registered: Feb 2002
Distribution: xubuntu 8.10
Posts: 225

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by crabboy
Do you not want the temp, or two statements?
Code:
array_splice( $data, $index, 1 );
$update_array[] = $data[0];
Actually, the whole point was to have one statement. In addition, I don't understand your code. The point in my code was to take the first element of the array returned by array_splice and assign it to $update_array. It looks to me like your code just gives me the first element of the $data array.

Quote:
Originally posted by msound

Yeah i think i over reacted just a little. I just come to these forums in the hopes of learning new things and helping other people. When someone gives me a crash course on proper discussion board etiquette I get a little annoyed. I understand how frustrating it can be to have someone hijack your thread but I didn't think my question strayed off topic. Sorry about the whole douche bag thing but that was actually out of an episode of southpark, gotta love southpark...
Actually, I don't like Southpark at all and never watch it, but apology accepted.

It was really my intention to help. If you noticed, I posted links that I thought would answer your question about the functions better than I could. And really, the only reason I mentioned anything about etiquette is that your reply was the first one. When I am looking for posts to reply to, I usually look for ones with zero replies first. Hence, posts with no replies get answer faster than those that have already had a reply or two. (if everyone thinks like me )

We are now 7 replies deep and only one of them has anything to do with my original question. Not being a "douche bag" just being overly practical.
 
Old 04-28-2004, 11:14 AM   #9
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,755

Rep: Reputation: 88
Yea, my code was wrong. I read the docs wrong and thought that the return value was the resulting array instead of the removed elements. It's safer to use a temp variable since you can check the size of the array instead of indexing it directly. If you always want the first element you can try:
Code:
$update_array[] = current(array_splice( $data, $index, 1 ));
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Accessing Large RAID Array FlyingPenguin128 Debian 1 05-16-2005 10:51 PM
Help accessing data on NTFS raid array Qwindelzorf Linux - Hardware 2 01-15-2005 02:34 PM
Java help (accessing array elemonts from another class or method) Tru_Messiah Programming 6 05-14-2004 09:20 AM
PHP array help? HappyDude Programming 1 10-13-2003 06:48 PM
php array gui10 Programming 2 03-26-2002 02:07 AM


All times are GMT -5. The time now is 06:41 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration