₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,134 members, 8,420,503 topics. Date: Thursday, 04 June 2026 at 10:27 PM

Toggle theme

Please Help With An Array Problem - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease Help With An Array Problem (1364 Views)

1 Reply (Go Down)

Please Help With An Array Problem by CRAZYMADMAN(op): 8:33pm On Dec 14, 2014
I am working on a web app that involves collecting data in arrays. Now I need to split the arrays in such a way that a variable holds the last array element of the array, while another holds the rest, so I run some database queries on it.
Please guys, any idea on how to go about it?
Re: Please Help With An Array Problem by Nobody: 8:35pm On Dec 14, 2014
ur user name and what u posted, I fear oooo.
just passing!!!!
Re: Please Help With An Array Problem by JackOfAllTrades: 9:07pm On Dec 14, 2014
CRAZYMADMAN:
I am working on a web app that involves collecting data in arrays. Now I need to split the arrays in such a way that a variable holds the last array element of the array, while another holds the rest, so I run some database queries on it.
Please guys, any idea on how to go about it?
what language are you working with
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 9:08pm On Dec 14, 2014
afolag:
ur user name and what u posted, I fear oooo.
just passing!!!!
what's wrong with that? abeg, programming is for everybody that have the interest
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 9:08pm On Dec 14, 2014
JackOfAllTrades:
what language are you working with
PHP
Re: Please Help With An Array Problem by JackOfAllTrades: 9:25pm On Dec 14, 2014
CRAZYMADMAN:
PHP
<?php
$myArray = array('red','yellow','green','blue');
$array_len = count ( $myArray );

$last_element = $myArray[ $array_len - 1];
unset( $myArray[ $array_len - 1] ) ;

// $myArray no longer holds blue

check if it works not tested oo
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 9:37pm On Dec 14, 2014
JackOfAllTrades:
<?php
$myArray = array('red','yellow','green','blue');
$array_len = count ( $myArray );

$last_element = $myArray[ $array_len - 1];
unset( $myArray[ $array_len - 1] ) ;

// $myArray no longer holds blue

check if it works not tested oo
thanks a lot for the help, but however I still need the last element because of the nature of the database query I need to run on the arrays
Re: Please Help With An Array Problem by JackOfAllTrades: 9:42pm On Dec 14, 2014
CRAZYMADMAN:
thanks a lot for the help, but however I still need the last element because of the nature of the database query I need to run on the arrays
I don't get you please explain more! did u read my code @all
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 9:46pm On Dec 14, 2014
JackOfAllTrades:
I don't get you please explain more! did u read my code @all
cool
sorry I didn't read the unset part well. the logic is sound and should work. thanks a lot
Re: Please Help With An Array Problem by JackOfAllTrades: 9:51pm On Dec 14, 2014
CRAZYMADMAN:
cool
sorry I didn't read the unset part well. the logic is sound and should work. thanks a lot
OK test it then, you welcome man cool
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 10:07am On Dec 15, 2014
JackOfAllTrades:
OK test it then, you welcome man cool
it worked perfectly with just a little modification. thanks
Re: Please Help With An Array Problem by CRAZYMADMAN(op): 4:22pm On Jan 01, 2015
just came across a PHP function that does exactly this! it's called


ARRAY_POP
Re: Please Help With An Array Problem by bot101(m): 4:43pm On Jan 02, 2015
A Simple Array Pop Will Do.
1 Reply

Php Array Problem [SOLVED]Simple Array Problem In PhpConverting Picture To Byte Array(blob) And Back To Picture234

Having A Challenge In C#Excel Macro VBA Programming.'if' By Davido - Javascript Version