-1

php

$new_position = $_POST['new_position'];
$new_positionpieces = explode(",", $new_position);
foreach ($new_positionpieces as $value) {
    echo $value."<br>";
}

cat_37<br>cat_36<br>

From what I gather if I were to echo $new_positionpieces[0] it would say cat_37

How would I be able to get that 0 into a variable inside my foreach so that If it were something like

echo $item.' - '.$value.'<br>'; and outputs 0 - cat_37 so that I am able to put it into my db

tadman
  • 200,744
  • 21
  • 223
  • 248
ngplayground
  • 18,559
  • 34
  • 93
  • 168

1 Answers1

3
foreach ($new_positionpieces as $key => $value) {
    echo $key . "=" . $value . "<br>";
}
Bill Karwin
  • 499,602
  • 82
  • 638
  • 795