fork download
  1. <?php
  2.  
  3. $params = array(
  4. 'email' => $PAGSEGURO_EMAIL,
  5. 'token' => $PAGSEGURO_TOKEN,
  6. 'creditCardToken' => $creditCardToken,
  7. 'senderHash' => $senderHash,
  8. 'receiverEmail' => $PAGSEGURO_EMAIL,
  9. 'paymentMode' => 'default',
  10. 'paymentMethod' => 'creditCard',
  11. 'currency' => 'BRL',
  12. 'extraAmount' => '1.00',
  13.  
  14. 'itemId1' => '0001',
  15. 'itemDescription1' => 'PHP Test',
  16. 'itemAmount1' => $numero,
  17. 'itemQuantity1' => 1,
  18.  
  19. 'itemId2' => '0002',
  20. 'itemDescription2' => 'PHP Test2',
  21. 'itemAmount2' => $numero,
  22. 'itemQuantity2' => 1
  23. );
  24.  
  25. $filter = preg_grep('/^itemId([0-9]{1,})/', array_keys( $params ));
  26. $result = array();
  27. for($i = 0; $i < count($filter); $i++)
  28. {
  29.  
  30. $result['itemId' . ($i + 1)] = $params['itemId' . ($i + 1)];
  31. $result['itemDescription' . ($i + 1)] = $params['itemDescription' . ($i + 1)];
  32. $result['itemAmount' . ($i + 1)] = $params['itemAmount' . ($i + 1)];
  33. $result['itemQuantity' . ($i + 1)] = $params['itemQuantity' . ($i + 1)];
  34.  
  35. }
  36.  
  37. var_dump($result);
Success #stdin #stdout #stderr 0.01s 82944KB
stdin
Standard input is empty
stdout
array(8) {
  ["itemId1"]=>
  string(4) "0001"
  ["itemDescription1"]=>
  string(8) "PHP Test"
  ["itemAmount1"]=>
  NULL
  ["itemQuantity1"]=>
  int(1)
  ["itemId2"]=>
  string(4) "0002"
  ["itemDescription2"]=>
  string(9) "PHP Test2"
  ["itemAmount2"]=>
  NULL
  ["itemQuantity2"]=>
  int(1)
}
stderr
PHP Notice:  Undefined variable: PAGSEGURO_EMAIL in /home/BcV0sm/prog.php on line 4
PHP Notice:  Undefined variable: PAGSEGURO_TOKEN in /home/BcV0sm/prog.php on line 5
PHP Notice:  Undefined variable: creditCardToken in /home/BcV0sm/prog.php on line 6
PHP Notice:  Undefined variable: senderHash in /home/BcV0sm/prog.php on line 7
PHP Notice:  Undefined variable: PAGSEGURO_EMAIL in /home/BcV0sm/prog.php on line 8
PHP Notice:  Undefined variable: numero in /home/BcV0sm/prog.php on line 16
PHP Notice:  Undefined variable: numero in /home/BcV0sm/prog.php on line 21