Hi. Relative php newbie but longtime coder in other langs.
Environment: PHP4.
Looking for a language construct or function that gives the opposite of
array(),
example:
function xyz($fmt, $argsarray)
{
// do something with each $argsarray
$result = sprintf( $fmt, un_array( $argsarray ) );
return $result;
}
Need to find something like "un_array" to produce a list of scalars from an
array so can be passed as arg list to sprintf and similar functions. Does
it exist? I've already thought of recursively building $fmt by picking off
first element of $argsarray, but looking for something cleaner and more
efficient.
Thx. 4 1957
I'm not sure if this is exactly what you're looking for, but implode()
will give you back a delimitated string of all the elements of the
array. Check it out here: [ http://php.net/implode ].
I noticed that Message-ID: <UQ_sd.881$sp.7 60@trndny08> from
comp.lang.php contained the following: Hi. Relative php newbie but longtime coder in other langs. Environment: PHP4.
Looking for a language construct or function that gives the opposite of array(),
foreach?
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
On Mon, 06 Dec 2004 15:24:36 GMT, "comp.lang. php" <re************ @nodomain.tld>
wrote: Hi. Relative php newbie but longtime coder in other langs. Environment: PHP4.
Looking for a language construct or function that gives the opposite of array(),
example:
function xyz($fmt, $argsarray) { // do something with each $argsarray
$result = sprintf( $fmt, un_array( $argsarray ) );
return $result; }
Need to find something like "un_array" to produce a list of scalars from an array so can be passed as arg list to sprintf and similar functions. Does it exist? I've already thought of recursively building $fmt by picking off first element of $argsarray, but looking for something cleaner and more efficient.
Untested:
function xyz($fmt, $argsarray)
{
array_unshift($ argsarray, $fmt);
$result = call_user_func_ array('sprintf' , $argsarray);
return $result;
}
--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
comp.lang.php wrote:
Need to find something like "un_array" to produce a list of scalars from an array so can be passed as arg list to sprintf and similar functions. Does it exist? I've already thought of recursively building $fmt by picking off first element of $argsarray, but looking for something cleaner and more efficient.
Sorry, don't think this quite exists as you want it. You're asking to
take a semantic feature (arrays storing multiple values) and convert it to
a syntactic feature (multiple magically named variables separated by
commas).
There is the extract() function, which is close, but still not quite what
you're asking for. http://www.php.net/manual/en/function.extract.php
what you want is:
vsprint, or vprintf
both of which take the list of arguments as arrays, not a variable list.
good ruck!
--
I am not an ANGRY man. Remove the rage from my email to reply. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Greg Ennis |
last post by:
If I run the following code:
Byte bytes = System.Text.Encoding.ASCII.GetBytes("test");
return BitConverter.ToString(bytes);
I get the string "74-65-73-74" back. My question is, what is the
easiest way to convert the string back to "test"?
Can it be done without breaking the string and using a loop, etc.? I
have tried many methods, but can't find a way without using a loop. It
|
by: bradleyp |
last post by:
Hi all,
I have a table (tblCodes) that has two fields: 'ID' and 'Code'.
A small portion of the table is as follows:
|-------------|
| tblCodes |
|-------------|
| ID | Code |
|------|------|
|
by: dssuresh6 |
last post by:
Whether browsing forward or backward can be done using a singly linked
list. Is there any specific case where a doubly linked list is needed?
For people who say that singly linked list allows traversal only in one
direction, I would say that using appropriate loops/recursion, traversal
in opposite direction is also possible. Then why the need for doubly
linked list?
--
|
by: Tony |
last post by:
Hi, I am looking for the opposite of wm_close, I assume
it's possibly wm_open but no info comes up with that term.
so, what is the opposite of WM_Close
Any ideas welcome
Tony
|
by: sabirah |
last post by:
My code does not seem to be working properly...
The game is b/w a human and the computer. The computer always goes
first. The computer chooses the first corner in the first turn. in
the comp's 2nd turn, it chooses the opposite corner if possible, if
that corner is not availabe, the computer chooses randomly. In the
computers next turns...it does the following:
1. checks for a winning position
else
2. blocks human from a winning...
| |
by: igor.tatarinov |
last post by:
Given a bunch of arrays, if I want to create tuples, there is
zip(arrays). What if I want to do the opposite: break a tuple up and
append the values to given arrays:
map(append, arrays, tupl)
except there is no unbound append() (List.append() does not exist,
right?).
Without append(), I am forced to write a (slow) explicit loop:
for (a, v) in zip(arrays, tupl):
a.append(v)
|
by: pereges |
last post by:
Ok, I have some problem with arrays which i want to use for storing
rays in my ray tracing project. please have a little patience to read.
I need to fire rays from a a rectangular plane. The rays are parallel
to each other so their direction is same but they differ in their
origin points or source location. I tried to determine the source
location by creating a grid of the rectangular plane. The rays are
going to be spaced from each...
|
by: Ganesh J. Acharya |
last post by:
Hi there,
I want to redesign my website and make that look professional.
I made this about 6 years ago with very little knowledge of internet.
Today I am getting about 4000 visitors a day for the same.
What are the things I need to keep in my mind when doing this process.
|
by: laszlobarta |
last post by:
Hello,
For saving 1 hour of your precious time use this function for parsing a text to a byte array:
/// <summary>
/// Converts the string representation of an array of numbers in a specified base to an
/// equivalent 8-bit unsigned integer array (byte).
/// </summary>
/// <param name="text">A System.String containing an array of numbers separated by '\r' or '\n' or '\t' or ' ' (space) or ','...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |