Solved

PHP Loop

Posted on 2013-11-18
2
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 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 110

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
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 …

734 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