473,788 Members | 2,837 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need opposite of array()

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.
Jul 17 '05 #1
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 ].

Jul 17 '05 #2
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/
Jul 17 '05 #3
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
Jul 17 '05 #4
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.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
16243
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
6
7400
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 | |------|------|
4
2932
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? --
5
2913
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
8
3801
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...
11
9053
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)
6
1550
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...
19
3316
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.
0
4129
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 ','...
0
9656
marktang
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...
0
9498
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,...
0
10366
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
9969
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
8993
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
6750
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
5399
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...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2894
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.