Array_merge funktioniert nicht

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Array_merge funktioniert nicht

    Hallo,
    ich habe eine HL 1 Class geschrieben und möchte 2 arrays verbinden. Mit array_push sieht das so aus:

    Quellcode

    1. Array
    2. (
    3. [type] => 109
    4. [gameip] => 89.106.86.23:27015
    5. [servername] => Warum liegt hier Stroh? 24/7 Dust2|AWP ON|Stroh 1
    6. [map] => de_dust2
    7. [gamedirectory] => cstrike
    8. [gamedescription] => Stroh Server 1
    9. [numberofplayers] => 25
    10. [maximumplayers] => 32
    11. [version] => 47
    12. [dedicated] => 100
    13. [os] => 108
    14. [password] => 0
    15. [ismod] => 1
    16. [0] => Array
    17. (
    18. [mod_urlinfo] => www.counter-strike.net
    19. [mod_urldl] =>
    20. [mod_nul] => 0
    21. [mod_version] => 1
    22. [mod_size] => 184000000
    23. [mod_svonly] => 0
    24. [mod_cldll] => 1
    25. )
    26. [1] => Array
    27. (
    28. [secure] => 1
    29. [numberofbots] => 0
    30. )
    31. )
    Alles anzeigen

    Ich möchte aber ein einfaches array haben und keine multi arrays, darum habe ich array_merge benutzt.
    Doch hier ist mein Problem ;)

    Quellcode

    1. array('lolool' => 'asd', 'roflrofl' => 'coflropter'), array('nlaaasd' => 'xid', 'blaaa' => 'norris'))

    Quellcode

    1. Array
    2. (
    3. [lolool] => asd
    4. [roflrofl] => coflropter
    5. [nlaaasd] => xid
    6. [blaaa] => norris
    7. )

    Das funktioniert ja super, aber die 2 arrays in meiner HL class wollen nicht :D

    Quellcode

    1. array_merge($unpacked, $mod);

    wird zu:

    Quellcode

    1. Array
    2. (
    3. [type] => 109
    4. [gameip] => 89.106.86.23:27015
    5. [servername] => Warum liegt hier Stroh? 24/7 Dust2|AWP ON|Stroh 1
    6. [map] => de_dust2
    7. [gamedirectory] => cstrike
    8. [gamedescription] => Stroh Server 1
    9. [numberofplayers] => 27
    10. [maximumplayers] => 32
    11. [version] => 47
    12. [dedicated] => 100
    13. [os] => 108
    14. [password] => 0
    15. [ismod] => 1
    16. )
    Alles anzeigen

    Var dumps:

    Quellcode

    1. array(13) {
    2. ["type"]=>
    3. int(109)
    4. ["gameip"]=>
    5. string(18) "89.106.86.23:27015"
    6. ["servername"]=>
    7. string(49) "Warum liegt hier Stroh? 24/7 Dust2|AWP ON|Stroh 1"
    8. ["map"]=>
    9. string(8) "de_dust2"
    10. ["gamedirectory"]=>
    11. string(7) "cstrike"
    12. ["gamedescription"]=>
    13. string(14) "Stroh Server 1"
    14. ["numberofplayers"]=>
    15. int(27)
    16. ["maximumplayers"]=>
    17. int(64)
    18. ["version"]=>
    19. int(47)
    20. ["dedicated"]=>
    21. int(100)
    22. ["os"]=>
    23. int(108)
    24. ["password"]=>
    25. int(0)
    26. ["ismod"]=>
    27. int(1)
    28. }
    29. array(7) {
    30. ["mod_urlinfo"]=>
    31. string(22) "www.counter-strike.net"
    32. ["mod_urldl"]=>
    33. string(0) ""
    34. ["mod_nul"]=>
    35. int(0)
    36. ["mod_version"]=>
    37. int(1)
    38. ["mod_size"]=>
    39. int(184000000)
    40. ["mod_svonly"]=>
    41. int(0)
    42. ["mod_cldll"]=>
    43. int(1)
    44. }
    Alles anzeigen
  • Quellcode

    1. $unpacked = $this->convert($buffer,array('type' => self::$BYTE,
    2. 'gameip' => self::$STRING,
    3. 'servername' => self::$STRING,
    4. 'map' => self::$STRING,
    5. 'gamedirectory' => self::$STRING,
    6. 'gamedescription' => self::$STRING,
    7. 'numberofplayers' => self::$BYTE,
    8. 'maximumplayers' => self::$BYTE,
    9. 'version' => self::$BYTE,
    10. 'dedicated' => self::$BYTE,
    11. 'os' => self::$BYTE,
    12. 'password' => self::$BYTE,
    13. 'ismod' => self::$BYTE));
    14. if ($unpacked['ismod'])
    15. {
    16. $mod = $this->convert($buffer,array('mod_urlinfo' => self::$STRING,
    17. 'mod_urldl' => self::$STRING,
    18. 'mod_nul' => self::$BYTE,
    19. 'mod_version' => self::$LONG,
    20. 'mod_size' => self::$LONG,
    21. 'mod_svonly' => self::$BYTE,
    22. 'mod_cldll' => self::$BYTE));
    23. array_merge($unpacked, $mod);
    24. }
    25. $unpacked2 = $this->convert($buffer,array('secure' => self::$BYTE,
    26. 'numberofbots' => self::$BYTE));
    27. array_merge($unpacked, $unpacked2);
    Alles anzeigen
  • Ich bin mir zwar nicht sicher, ob es vielleicht nur ein kleiner Tippfehler war, aber du hast bei beiden Funktionsaufrufen vergessen die Funktionsrückgabe an eine Variable zu übergebe.

    Quellcode

    1. $unpacked = $this->convert($buffer, array('type' => self::$BYTE,
    2. 'gameip' => self::$STRING,
    3. 'servername' => self::$STRING,
    4. 'map' => self::$STRING,
    5. 'gamedirectory' => self::$STRING,
    6. 'gamedescription' => self::$STRING,
    7. 'numberofplayers' => self::$BYTE,
    8. 'maximumplayers' => self::$BYTE,
    9. 'version' => self::$BYTE,
    10. 'dedicated' => self::$BYTE,
    11. 'os' => self::$BYTE,
    12. 'password' => self::$BYTE,
    13. 'ismod' => self::$BYTE));
    14. $unpack = array();
    15. if ($unpacked['ismod']) {
    16. $mod = $this->convert($buffer, array('mod_urlinfo' => self::$STRING,
    17. 'mod_urldl' => self::$STRING,
    18. 'mod_nul' => self::$BYTE,
    19. 'mod_version' => self::$LONG,
    20. 'mod_size' => self::$LONG,
    21. 'mod_svonly' => self::$BYTE,
    22. 'mod_cldll' => self::$BYTE));
    23. $unpacked = array_merge($unpacked, $mod);
    24. }
    25. $unpacked2 = $this->convert($buffer, array('secure' => self::$BYTE, 'numberofbots' => self::$BYTE));
    26. $unpack = array_merge($unpacked, $unpacked2);
    27. var_dump($unpack);
    Alles anzeigen
    MfG dynambee