Question: I need one help.I need to push one array object value into another array object in each iteration using PHP.I am explaining my code below.

```
for($i=0;$i<$len;$i++){
 while($report=mysqli_fetch_assoc($reportqry)){
        $result[]=$report;
    }
  //$arry
}

```

Here i need the `$result` will push into `$arry` in each iteration of the loop.Please help me.

Answer: 
You have to remove the semicolon (`;`) after the temination condition of your while loop. `;` is the end of an statement, after that a new statment beginns. Apart from this your `return` statement would be inside the `while` loop. Remove it outside the loop. Adapt your code like this:

```
int len(char p[]) {
    int count = 0;
    while (*p != '\0')
    {
        count++;
        p++;
    }
    return count;
}

```

Further you have to read a string from input into your dynamicly allocated array of `char`:

```
int main() {

    int array_size = 100;
    char *p=new char[array_size];      // allocate memory

    cout << "Type a phrase" << endl;
    cin >> p;                          // read string into allocated memory

    cout << "Your phrase was " << len(p) << " characters long." << endl;

    delete p;                          // free memory
    return 0; 
}

```

The function `strlen` gives you the length of a `\0`-terminated string.

```
#include <string.h>

int main() {

    int array_size = 100;
    char *p=new char[array_size];     // allocate memory

    cout << "Type a phrase" << endl;
    cin >> p;                         // read string into allocated memory

    cout << "Your phrase was " << strlen(p) << " characters long." << endl;

    delete p;                         // free memory
    return 0; 
}

```

**But I recommend to use `std::string`:**

```
#include <string>

int main() {

    std::string str;
    cout << "Type a phrase" << endl;
    cin >> str;

    cout << "Your phrase was " << str.size() << " characters long." << endl;
    return 0; 
}

```

`std::string` represents a sequences of characters with dynamic length.
First problem: you cannot use array\_size till it has been initialized.

> 
> `char* a = new char [array_size]`
> 
> 
> 

since array\_size has not been initialized and has garbage data in it, you have no idea how big that array is going to be.

that's why first you have to initialize `array_size`, and only after allocate your `char array`.

like

```
int array_size = 0 //no reason to have this variable as global, but that's up to you 
char *a = nullptr; //same

int main()
{
    cin >> array_size;

    if (array_size <= 0) //make sure the input is valid and not negative
         return 0;       

    a = new char[array_size];

    //now you can work on your newly allocated array of characters

    //the number of characters the array has equals to the array_size variable.

    delete[] a;
    return 0;
}

```

your len function checks for a '\0' character, but again, you have not initialized that char array either, so it contains garbage data. therefore sometimes you may get a result of len 5, 10, 502043, anything can happen really (undefined behavior).