Hi, I'm using PHP 4. I have two scalar variables, each containing
comma separated lists of numbers
$big_list = "1,2,3,4,5,6,7,8";
$small_list = "5,4,6";
"$small_list" will always contain less elements than "$big_list" and
all of "$small_list"s numbers will be included in "$big_list". I want
to get a variable that contains "$big_list" minus "$small_list". In
the above example, the resulting varaible would contain "1,2,3,7,8".
Any short cuts are greatly appreciated.
Thanks, - Dave 2 1098 la***********@zipmail.com said the following on 11/05/2006 15:32: Hi, I'm using PHP 4. I have two scalar variables, each containing comma separated lists of numbers
$big_list = "1,2,3,4,5,6,7,8"; $small_list = "5,4,6";
"$small_list" will always contain less elements than "$big_list" and all of "$small_list"s numbers will be included in "$big_list". I want to get a variable that contains "$big_list" minus "$small_list". In the above example, the resulting varaible would contain "1,2,3,7,8".
It's easier to deal with arrays than strings, so convert your lists to
arrays using explode(). Then use some combination of the PHP
array-handling functions; array_diff() might do the job you're after.
--
Oli la***********@zipmail.com wrote: Hi, I'm using PHP 4. I have two scalar variables, each containing comma separated lists of numbers
$big_list = "1,2,3,4,5,6,7,8"; $small_list = "5,4,6";
"$small_list" will always contain less elements than "$big_list" and all of "$small_list"s numbers will be included in "$big_list". I want to get a variable that contains "$big_list" minus "$small_list". In the above example, the resulting varaible would contain "1,2,3,7,8".
Any short cuts are greatly appreciated.
Thanks, - Dave
This one-liner should work:
print implode(",", array_diff(explode(",", $big_list), explode(",",
$small_list)));
However, if you're using it in code you (or someone else!) would need to
maintain in the future, it would be wise to expand it to increase
readability. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Matthew Thorley |
last post by:
My friend sent me an email asking this:
> I'm attemtping to decide which scripting language I should master and
> was wondering if it's possible to do
> these unixy awkish commands in python:...
|
by: Mike Maxwell |
last post by:
When I invoke readline() in a for loop, why does it return a series of
one-char strings, rather than the full line?
>>> for sL in sys.stdin.readline(): print sL
....
abc
a
b
c
|
by: vj |
last post by:
I'm trying to create a semi restricted env where users are not able to
bring my application down. I know the following:
100000000**10000000
will not be caught by signal.alarm since it is...
|
by: Alex |
last post by:
Hi all,
The subject says pretty much all, i would very appreciate an answer. I
tried to search the various forums and groups, but didn't find any
specific answer...
Thanks,
Alex.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
| |