Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP Loop

Posted on 2013-11-18
2
Medium Priority
?
306 Views
Last Modified: 2014-04-22
need code to do the following in php

Specify a max nbr to loop thru like 1 thru 1000
Specify a start value for index any numeric value
Each time index should increase by 1
2nd value should be a random 10 digit nbr

the output needs to look like this

$cb->set("index", $randomnumber);
0
Comment
Question by:AlexPonnath
  • 2
2 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1500 total points
ID: 39657771
<?php // RAY_temp_alexponnath.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28297482.html

/**
 * Specify a max nbr to loop thru like 1 thru 1000
 * Specify a start value for index any numeric value
 * Each time index should increase by 1
 * 2nd value should be a random 10 digit nbr
 * the output needs to look like this: $cb->set("index", $randomnumber);
 */

// THE CLASS DEFINITION FOR "$cb"
Class Cb
{
    public function set($index, $randomnumber)
    {
        $this->data[$index] = $randomnumber;
    }
}

// INSTANCE OF THE CB CLASS
$cb = new CB;

// RANGE OF TEN DIGIT NUMBERS
$lo = 1000000000;
$hi = 9999999999;

// NUMBER OF ELEMENTS TO CREATE
$lim = 32;

// STARTING INDEX
$ndx = 16;

// THE ARRAY KEYS
$arr = range($ndx, $ndx+$lim);
foreach ($arr as $key)
{
    $cb->set($key, rand($lo, $hi));
}

// SHOW THE WORK PRODUCT
echo '<pre>';
print_r($cb);

Open in new window

Best regards, ~Ray
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40016129
@AlexPonnath: Please see the EE grading guidelines:
http://support.experts-exchange.com/customer/portal/articles/481419

Out of your last ten questions, you've given only one grade of "A" -- a behavior that is astonishingly out of step with an online community where the default and expected grade is "A" unless the responses are deficient.

In the instant case you got a tested and working code example that does exactly what you asked for, and you got it within 15 minutes of posting the question.  So I think you owe an explanation for the marked down grade.  Specifically, what were you expecting that you did not get?

Standing by to hear back from you! ~Ray
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question