473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

PHP Single Array to Multi Array Problem

I have exploded a file line into a single dimensioned array. I want to take the contents of the single deminsioned array and separate it out into a multi-dimensioned array.

In the for loop I have code like this:

$arr1[0][$j] = $arr2[$j];

where the j index is changing. The result is only the first character of the arr2 is being deposited into arr1 for each element of the array. arr2 is still intact with complete field values.

What is causing this and is there something I should be doing (such as a cast...tried casting arr2 with (string) and that didn't work) to insinuate a complete field transfer?
Jun 11 '09 #1
5 2411
Dormilich
8,658 Expert Mod 8TB
try
Expand|Select|Wrap|Line Numbers
  1. $arr1[0] = $arr2;
what does that give?
Jun 11 '09 #2
Atli
5,058 Expert 4TB
If Dormilich's solution doesn't work, post the entire loop here. Maybe there is something wrong with the loop itself.
Jun 11 '09 #3
I need to extract the field to the second part of the multi-field array (arr1[0][$j]).

Further info:

I tried putting the information into a variable and then loading the array from the variable and the destination array (arr1) still is truncating all but the first character.

$holdingCell = $arr2[$j];
$arr1[0][$j] = $holdingCell;

echo $holdingCell;

what print_r shows is the first character of each field....

Is there something within PHP that needs the second array of a multi-array dimensioned?

I set up $arr1 = array(array());
Jun 11 '09 #4
Dormilich
8,658 Expert Mod 8TB
@mcafeedan
that's what the code is supposed to do. I just didn't bother to copy the elements one by one when I can pass over the whole array.

@mcafeedan
then try
Expand|Select|Wrap|Line Numbers
  1. $arr1 = array($arr2);
Jun 11 '09 #5
Well, I was able to figure out the solution by playing around with the indexes and coming to the conclusion that the second index was not necessary. As soon as I dropped that index PHP moved everything as desired. Solution looked like this:

arr1[0] = arr2[j];

Suggesting that PHP add additional items to a multi-dimensioned array the same way it does in single dimensioned arrays where not specifying an index means to add to the array list...in this case the undefined index.

Thanks for your input....
Jun 15 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: DLP22192 | last post by:
I have the following single-line if statement that is evaluating true even though it shouldn't. I have never seen this before and I am concerned that this can happen in other areas of my code. ...
2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
1
by: herrcho | last post by:
#include <stdio.h> int multi; int main() { printf("\nmulti = %u",multi); printf("\nmulti = %u",multi); printf("\n&multi = %u\n",&multi); return 0;
2
by: Salman Khilji | last post by:
After reading all the FAQs, I cannot solve the following problem: I have a pointer of type double. I am supposed to 1) Allocate memory for it assuming that the pointer will be pointing to a...
8
by: Michel Rouzic | last post by:
I had a program that worked perfectly, and that read .wav files. I changed something so the tags of the wave file, instead of being each in a different variable, are all in an array, called tag. i...
0
by: Kirk Marple | last post by:
an external API that we're using is giving me back video data in a multi-dimensional Array (not byte, just System.Array). so, for an HD quality video, the data is organized as of bytes. i know...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
24
by: Kavya | last post by:
int main (){ int a={{1,2,3},{4,5,6}}; int (*ptr)=a; /* This should be fine and give 3 as output*/ printf("%d\n",(*ptr)); ++ptr;
4
by: jgendr2 | last post by:
So here is my problem I do not know if there is another way to solve this without using arrays....but I am assuming that I DO need to use arrays....Anyways FIRST ARRAY (SINGLE): $results =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.