Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:06:40+00:00 2026-06-18T12:06:40+00:00

I need to add data to EACH array within a multidimensional array. Here is

  • 0

I need to add data to EACH array within a multidimensional array. Here is my code thus far:

<?php 
//Arrays
$rsIdeas_array = array();

//Query Database
mysql_select_db($database_connFormula, $connFormula);
$query_rsIdeas = "SELECT * FROM ideas";
$rsIdeas = mysql_query($query_rsIdeas, $connFormula) or die(mysql_error());
$row_rsIdeas = mysql_fetch_assoc($rsIdeas);
$totalRows_rsIdeas = mysql_num_rows($rsIdeas);

//loop bizideas into array
do {
$calculated = ($row_rsIdeas['monthlysearches'] * 9);
array_push($rsIdeas_array, $row_rsIdeas);
array_splice($rsIdeas_array, 7, 0, $calculated);
} while ($row_rsIdeas = mysql_fetch_assoc($rsIdeas));

print_r($rsIdeas_array);

Here is what I get:

Array
(
[0] => Array
    (
        [ideaID] => 1
        [userID] => 1
        [bizidea] => Business Idea 1
        [bizexplained] => Business Idea 1 Explanation
        [bizmodel] => Utility
        [repkeyword] => Keyword 1
        [monthlysearches] => 33100
        [advcomp] => 0.95
        [startease] => 6
    )

[1] => 297900
[2] => Array
    (
        [ideaID] => 2
        [userID] => 1
        [bizidea] => Business Idea 2
        [bizexplained] => Business Idea 2 Explained
        [bizmodel] => Service
        [repkeyword] => Keyword 2
        [monthlysearches] => 6600
        [advcomp] => 0.93
        [startease] => 8
    )

[3] => 59400

)

What I need however, is each previously created array to include the calculated values, like this:

Array
(
[0] => Array
    (
        [ideaID] => 1
        [userID] => 1
        [bizidea] => Business Idea 1
        [bizexplained] => Business Idea 1 Explanation
        [bizmodel] => Utility
        [repkeyword] => Keyword 1
        [monthlysearches] => 33100
        [calculated] => 297900 //Here is where I need the calculated values
        [advcomp] => 0.95
        [startease] => 6
    )

[1] => Array
    (
        [ideaID] => 2
        [userID] => 1
        [bizidea] => Business Idea 2
        [bizexplained] => Business Idea 2 Explained
        [bizmodel] => Service
        [repkeyword] => Keyword 2
        [monthlysearches] => 6600
        [calculated] => 59400 //Here is where I need the calculated values
        [advcomp] => 0.93
        [startease] => 8
    )
)

Where am I going wrong?

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:06:41+00:00Added an answer on June 18, 2026 at 12:06 pm

    You don’t need to do any splicing.

    do {
      $row_rsIdeas['calculated'] = ($row_rsIdeas['monthlysearches'] * 9);
      array_push($rsIdeas_array, $row_rsIdeas);
    } while ($row_rsIdeas = mysql_fetch_assoc($rsIdeas));
    

    Yes, it’s that easy.

    — edit —

    If you absolutely must have the columns in a particular order, you can do something like this:

    $row_rsIdeas['calculated'] = ($row_rsIdeas['monthlysearches'] * 9);
    $row_rsIdeas = array(
      'ideaID' => $row_rsIdeas['ideaId'],
      'userID' => $row_rsIdeas['userId'],
      'bizidea' => $row_rsIdeas['bizidea'],
      // and so on
    );
    array_push($rsIdeas_array, $row_rsIdeas);
    

    OR

    $row_rsIdeas['calculated'] = ($row_rsIdeas['monthlysearches'] * 9);
    uksort($row_rsIdeas, function($col1, $col2)) {
       $cols = array('ideaID' => 0, 'userID' => 1, 'bizidea' => 2, ...); //etc
       return ($cols[$col1] > $cols[$col2]);  // this might be backwards, trying reversing
    }
    array_push($rsIdeas_array, $row_rsIdeas);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add some details to an array without overwriting the old data.
I have a form and I need to add some data from database before
I need to add conditions depending on params data. @users = User.where('id', params[:id]) unless
With df <- data.frame(v1=c(1:5), v2=c(9,32,6,17,11)) I need to add a new column v3 with
I have a table of data that I need to dynamically add a column
I am using the Add-on builder and I need to receive binary data (image).
I need some help with allocating arrays dynamically. I have an array whose size
I am trying to add a property to javascript nested array object... I need
I need add Auto complete on apex Tabular Form. there is a column as
I need add a new user group for mediawiki. The new group has more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.