2

Using this solution. I am trying to format a number with leading zero's. The length is 12 digits. The starting is 00000000001 and if the number is 10 then 000000000010 and so on. I have tried below

 OGP-<?php $model=$dataProvider->getModels()[0]; 
 str_pad($model['OGP_Serial_No'], 12, '0', STR_PAD_LEFT)?>

But it's giving me empty result OGP-.

How can I achieve this?

Any help would be highly appreciated.

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
Moeez
  • 494
  • 9
  • 55
  • 147
  • The result of the str_pad() is going nowhere. You need to save the result to a variable first or echo the result. –  Nov 20 '17 at 07:02
  • `OGP-getModels()[0];$value = implode(',', $model); str_pad($value, 12, '0', STR_PAD_LEFT)?` still giving empty result – Moeez Nov 20 '17 at 07:07

2 Answers2

1

Try this

<?php 
if(isset($dataProvider->getModels()[0]) && $dataProvider->getModels()[0] != array()){

    $model = $dataProvider->getModels()[0]; 
    $OGP_Serial_No = $model['OGP_Serial_No'];
    $myNumber = "OGP-".str_pad($OGP_Serial_No, 12, '0', STR_PAD_LEFT);

}else{
    $myNumber = "OGP-".str_pad(1, 12, '0', STR_PAD_LEFT);
}
echo $myNumber;
?>
Naim Malek
  • 1,186
  • 1
  • 11
  • 21
0

Try check the real content eg: using var_dump()

<?php 
      $models = $dataProvider->getModels(); [0]; 
      $myString  = 'OGP-' . str_pad( $models[0]['OGP_Serial_No'] , 12, '0', STR_PAD_LEFT); 
      var_dump($myString);
?>
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107