Advertisement
Guest User

Untitled

a guest
Dec 11th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /**
  2. * @var PDO
  3. */
  4.  
  5. $array = [
  6. 45 => [
  7. 'curl_options' => [
  8. CURLOPT_URL => 'http:',
  9. CURLOPT_RETURNTRANSFER => true,
  10. CURLOPT_POST => true,
  11. ],
  12. 'curl_postfield' => 'id',
  13. 'status_pattern' => '/[da-z]{13}s*(.+)/isu'
  14. ],
  15. 46 => [
  16. 'curl_options' => [
  17. CURLOPT_URL => 'http:',
  18. CURLOPT_RETURNTRANSFER => true,
  19. CURLOPT_POST => true,
  20. ],
  21. 'curl_postfield' => 'post',
  22. 'status_pattern' => '/[da-z]{10}s*(.+)/isu'
  23. ]
  24. ];
  25.  
  26. $array = [];
  27. /** @var $array ExampleClass[] */
  28.  
  29. foreach ($array as $object) {
  30. // $object->getS... сработает автодополнение
  31. $object->getSomething();
  32. }
  33.  
  34. class ExampleClass
  35. {
  36. /** @var ExampleEmbeddedClass[] */
  37. public $list = [];
  38.  
  39. public function getSomething() {}
  40. }
  41.  
  42. class ExampleEmbeddedClass
  43. {
  44. public $property = 1;
  45. }
  46.  
  47. $array = [
  48. 42 => new ExampleClass(),
  49. ];
  50. /** @var $array ExampleClass[] */
  51. $array[42]->list[] = new ExampleEmbeddedClass();
  52.  
  53. $cleanArray = json_decode(json_encode($array), true);
  54.  
  55. var_export($cleanArray);
  56.  
  57. array (
  58. 42 =>
  59. array (
  60. 'list' =>
  61. array (
  62. 0 =>
  63. array (
  64. 'property' => 1,
  65. ),
  66. ),
  67. ),
  68. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement