473,322 Members | 1,911 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,322 software developers and data experts.

Concatenating problem while Iteration

hsriat
1,654 Expert 1GB
I have an array, and I want to suffix "0" to the first 10 elements and "1" to the remaining array elements. So what I did was:

First.[php]for($i=0; $i<count($set_name); $i++)
$set_name[$i] .= $i < 10 ? "0" : "1";[/php]Error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 16 bytes)

Second[php]foreach($set_name as $i=>$s_name)
$set_name[$i] .= $i < 10 ? "0" : "1";[/php]Error: Suffixing "0" to all the elements.

Third[php]foreach($set_name as $i=>$s_name)
$set_name[$i] = $i < 10 ? $s_name."0" : $s_name."1";[/php]Error: Suffixing "0" to all the elements.


Fourth.... can anyone tell?
May 5 '08 #1
2 1200
ronverdonk
4,258 Expert 4TB
What kind of array are you processing?
I tried the first one with 20 entries and it worked perfectly well.[php]<?php
$set_name=array("aa","ba","ca","da","ea","fa", "ga","ha","ia","ja","ka", "la","ma","na","oa", "pa","qa","ra","sa","ta",);
for($i=0; $i<count($set_name); $i++)
$set_name[$i] .= $i < 10 ? "0" : "1";
echo '<pre>'; print_r($set_name);
?>[/php]

Ronald
May 5 '08 #2
hsriat
1,654 Expert 1GB
Hey, thanks for trying.

I tried everything out!.. list(), each() and array_walk(). But didn't get any success.
But after pulling my hair on this for about 90 min, I came to know that the keys of the array are no more as 1,2,3,4..... but I had converted them to HEX codes. ie '0x0001', '0x0002', '0x0003' .... so it was considering them as strings and thus was giving all these problems.

Now I sorted it out and had a good time laughing on my miserableness. Actually its 2:00AM here, and you can expect that from me at this time.

Thanks and regards,
Harpreet
May 5 '08 #3

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

Similar topics

14
by: foodic | last post by:
i am fresher to C++ programming, and I just want to learn Concatenating Calls, I have written a program, class SetMe { public: void setX(int x) {_x = x;} void setY(int y) {_y = y;} void...
7
by: Mahesh Kumar Reddy.R | last post by:
Hi Can any body resolve this.. In what cases one of the loop constructs better than other interms of speed , space and any other (redability). thanks mahesh
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
1
by: Glenton | last post by:
Hi All I was writing a bit of code to solve Euler Project #90, and came across the need to iterate through all combinations of a particular list. Any improvements would be most welcome, but I...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.