-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
  • 208,517
  • 23
  • 234
  • 262
ngplayground
  • 20,365
  • 36
  • 94
  • 173

1 Answers1

3
foreach ($new_positionpieces as $key => $value) {
    echo $key . "=" . $value . "<br>";
}
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828