i Want to know if this is possible. I have an array say

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
finesofttechnologies
Forum Newbie
Posts: 8
Joined: Wed Apr 02, 2014 3:32 am
Location: New delhi

i Want to know if this is possible. I have an array say

Post by finesofttechnologies »

$colors = array( 'red', 'green' )

I want to create an array from above array as

$colors = array( 'red', 'red (2)', 'red (3)', 'red (4)','red (5)'
'green', 'green (2)', 'green (3)', 'green (4)', 'green (5)' );
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: i Want to know if this is possible. I have an array say

Post by requinix »

If you want literally "red (2)" and such, you'll need to code that yourself using a couple loops: one over $colors and another counting from 2 to however many times you want each color repeated. Append each thing to a new array and you're done.
Post Reply