Jump to content

billyb14

New Members
  • Posts

    1
  • Joined

  • Last visited

billyb14's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello, I don't know if this is what you want. And I'm sure the code could be more efficient, but is this what you want to do? $list = array(6,5,4,3); //Create an array with the numbers $out_arr = array(); //Create an array to hold the answers foreach( $list as $num ){ //Cycle through first array $tmp = ""; //Create temp string to hold number for ($i = $num; $i > 0; $i --){ //Loop to add $num as a string to the temp string we just made, $num times $tmp .= "$num"; } $newnum = (int) $tmp; //Create temp number to add to array array_push($out_arr, $newnum); //Add answer to array } print_r($out_arr); //Echo array on screen (for testing) I'm sorry I can't help any more, I don't really understand the question. Good Luck! EDIT: I just read you question again, and did you want that as a function as opposed to a loop that runs through an array? Maybe like this? function counter_thing($num){ //$num is the input number $tmp = ""; //Create temp string to hold answer for ($i = $num; $i > 0; $i --){ //Add $num to temp string $num times $tmp .= "$num"; } return = (int) $tmp; //Convert temp string into an int (number) and return it. } Again, I still don't completely understand what you want, nor do I understand what the function is meant to be for. (That's why I called it "counter_thing") Hope this helps
  2. Hello Afzal, My name is Billy and I am new to these fourms too. I have taught my self PHP, I'm no professional but I know my way around more than some people. I hope to be able to help you Afzal, as well as others on this fourm
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.