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 6738381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:21:43+00:00 2026-05-26T11:21:43+00:00

Trying to figure out how to pull values for a specific index in an

  • 0

Trying to figure out how to pull values for a specific index in an array, manipulate it, then replace the value back into the array in its original position.

I’ve got an array from a form POST that uploaded a CSV:

if(isset($_POST['submit'])){
  $csvFile = $_FILES['csv']['tmp_name'];
  $handle = fopen($csvFile,"r");
  $fileop = fgetcsv($handle,1000,",");
}

Uploaded CSV file usually has 20 to 100 rows with 5 columns (indexed keys). Here’s an example of only 2 records from a print_r($fileop) while loop.

HTML Display:

Array
(
    [0] => Chevy
    [1] => Sedan
    [2] => Malibu
    [3] => <a href="#"><img href="http://www.domain.co/logo.png" alt="Pic" /></a>
    [4] => 8000.00
)
Array
(
    [0] => Chevy
    [1] => Pickup
    [2] => 2500
    [3] => <a href="#"><img href="http://www.domain.co/logo.png" alt="Pic" /></a>
    [4] => 18000.00
)

Here’s some examples of what I’m trying to accomplish.

EDIT #1:

$imageLink = stripslashes($fileop[3]);
str_replace("http://www.domain.co/logo.png","/images/logo.png",$imageLink);

EDIT #2:

$model = stripslashes($fileop[2]);
$preHTML = <div id="model" style="clear:both"><strong>;
$postHTML = </strong></div>;
$fullHTML = $preHTML . $model . $postHTML;

NEW HTML Display:

Array
(
    [0] => Chevy
    [1] => Sedan
    [2] => <div id="model" style="clear:both"><strong>Malibu</strong></div>
    [3] => <a href="#"><img href="/images/logo.png" alt="Pic" /></a>
    [4] => 8000.00
)
Array
(
    [0] => Chevy
    [1] => Pickup
    [2] => <div id="model" style="clear:both"><strong>2500</strong></div>
    [3] => <a href="#"><img href="/images/logo.png" alt="Pic" /></a>
    [4] => 18000.00
)

BIG QUESTION: How do I return these manipulated values back to the array?

I’ve been searching for a few hours on this and I’m overloaded now and more confused. Any help is much appreciated!

UPDATE:

I’ve been playing with some answers provided below and haven’t had much luck so far. It does work as far as updating a single array in the “stacked” arrays that are retrieved from the CSV file but I can’t get it to update all the arrays for a specific key and retain the “stacked” arrays.

I’m not sure I’m using the right terminology for “stacked arrays” but basically if I loop thru the stacked arrays from the CSV I get many print outs of individual arrays so when it comes time to INSERT into MySQL DB, I can loop thru the arrays and write them in as individual records.

I tried the following and it lost all the other arrays and only kept the 1st one that it modified:

while(($fileop = fgetcsv($handle,1000,",")) != false){
    $model = stripslashes($fileop[2]);
    $fileop[2] = '<div id="model" style="clear:both"><strong>'.$model.'</strong></div>';
}

Now when doing the following print I don’t get all the arrays:

<pre>
<?php
while(($fileop = fgetcsv($handle,1000,",")) != false){
    print_r($fileop);
}
?>
</pre>

HTML Result (Only 1 array, all other “stacked arrays” are lost and don’t print):

Array
(
    [0] => Chevy
    [1] => Sedan
    [2] => Malibu
    [3] => <a href="#"><img href="http://www.domain.co/logo.png" alt="Pic" /></a>
    [4] => 8000.00
)
  • 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-05-26T11:21:43+00:00Added an answer on May 26, 2026 at 11:21 am

    the following should work for you:

    <?php
    $arr = array();
    while(($fileop = fgetcsv($handle,1000,",")) != false){
        $arr[] = $fileop;
    }
    
    
    foreach ( $arr as $k => $v ) {
        $model = stripslashes($v[2]);
        $preHTML = '<div id="model" style="clear:both"><strong>';
        $postHTML = '</strong></div>';
        $fullHTML = $preHTML . $model . $postHTML;
        $arr[$k][2] = $fullHTML;
    
        $imageLink = stripslashes($v[3]);
        $arr[$k][3] = str_replace("http://www.domain.co/logo.png","/images/logo.png",$imageLink);
    }
    
    print_r($arr);
    

    A sample output:

    Array
    (
        [0] => Array
            (
                [0] => Chevy
                [1] => Sedan
                [2] => <div id="model" style="clear:both"><strong>Malibu</strong></div>
                [3] => <a href="#"><img href="/images/logo.png" alt="Pic" /></a>
                [4] => 8000.00
            )
    
        [1] => Array
            (
                [0] => Chevy
                [1] => Pickup
                [2] => <div id="model" style="clear:both"><strong>2500</strong></div>
    
                [3] => <a href="#"><img href="/images/logo.png" alt="Pic" /></a>
                [4] => 18000.00
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how pull select values from a table column, but
Im stuck trying to figure out how to pull the information from my pre-populated
So I've been trying to figure out the most efficient way to pull off
I'm trying to figure out how to pull different data scenarios from my table
I'm trying to figure out how to pull all the records in my set
I have spent WAY too much time trying to figure out how to pull
I'm trying to figure out how to iterate through a document and pull all
I am trying to figure out the best way, using PHP, to pull a
Trying to figure out an equation to get the current group a page would
Trying to figure out the best way to set up collection lists for users

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.