简体   繁体   中英

Last element of array

Im trying to go through array to create a new one from it. Trying to log everything while runnging this code:

$this->writeToLog(print_r($this->assembledText, true), 'ass.log');
foreach ($this->assembledText as $paragraphsKey => $paragraphs) {
    $this->writeToLog("Paragraph Key:".$paragraphsKey.print_r($paragraphs, true), 'para.log'); 
    $i = 0;
    foreach ($paragraphs as $words) {
        $newText[$paragraphsKey][$i] = $words;
        $i++;
    }
}

Here Im logging the text before i go through, and here what i have so far:

ass.log gives me this:

[2019-05-18 20:32:38] Array
(
    [0] => Array
        (
            [0] => One
            [1] => thing
            [2] => was
            [3] => certain,
            [4] => that
            [5] => the
            [6] => white
            [7] => kitten
            [8] => had
            [9] => had
            [10] => nothing
            [11] => to
            [12] => do
            [13] => with
            [14] => it:
            [15] => —
            [16] => it
            [17] => was
            [18] => the
            [19] => black
            [20] => kitten’s
            [21] => fault
            [22] => entirely.
            [23] => For
            [24] => the
            [25] => white
            [26] => kitten
            [27] => had
            [28] => been
            [29] => having
            [30] => its
            [31] => face
            [32] => washed
            [33] => by
            [34] => the
            [35] => old
            [36] => cat
            [37] => for
            [38] => the
            [39] => last
            [40] => quarter
            [41] => of
            [42] => an
            [43] => hour
            [44] => (and
            [45] => bearing
            [46] => it
            [47] => pretty
            [48] => well,
            [49] => considering);
            [50] => so
            [51] => you
            [52] => see
            [53] => that
            [54] => it
            [55] => couldn’t
            [56] => have
            [57] => had
            [58] => any
            [59] => hand in
            [61] => the
            [62] => mischief.
            [63] => 
        )

    [1] => Array
        (
            [0] => 
            [1] => The
            [2] => way
            [3] => Dinah
            [4] => washed
            [5] => her
            [6] => children’s
            [7] => faces
            [8] => was
            [9] => this:
            [10] => first
            [11] => she
            [12] => held
            [13] => the
            [14] => poor
            [15] => thing
            [16] => down
            [17] => by
            [18] => its
            [19] => ear
            [20] => with
            [21] => one
            [22] => paw,
            [23] => and
            [24] => then
            [25] => with
            [26] => the
            [27] => other
            [28] => paw
            [29] => she
            [30] => rubbed
            [31] => its
            [32] => face
            [33] => all
            [34] => over,
            [35] => the
            [36] => wrong
            [37] => way,
            [38] => beginning
            [39] => at
            [40] => the
            [41] => nose:
            [42] => and
            [43] => just
            [44] => now,
            [45] => as
            [46] => I
            [47] => said,
            [48] => she
            [49] => was
            [50] => hard
            [51] => at
            [52] => work on
            [54] => the
            [55] => white
            [56] => kitten,
            [57] => which
            [58] => was
            [59] => lying
            [60] => quite
            [61] => still
            [62] => and
            [63] => trying
            [64] => to
            [65] => purr
            [66] => —
            [67] => no
            [68] => doubt
            [69] => feeling
            [70] => that
            [71] => it
            [72] => was
            [73] => all
            [74] => meant
            [75] => for
            [76] => its
            [77] => good.
            [78] => 
        )

    [2] => Array
        (
            [0] => 
            [1] => But
            [2] => the
            [3] => black
            [4] => kitten
            [5] => had
            [6] => been
            [7] => finished
            [8] => with
            [9] => earlier
            [10] => in
            [11] => the
            [12] => afternoon,
            [13] => and
            [14] => so,
            [15] => while
            [16] => Alice
            [17] => was
            [18] => sitting
            [19] => curled
            [20] => up
            [21] => in
            [22] => a
            [23] => corner
            [24] => of
            [25] => the
            [26] => great
            [27] => arm-chair,
            [28] => half
            [29] => talking
            [30] => to
            [31] => herself
            [32] => and
            [33] => half
            [34] => asleep,
            [35] => the
            [36] => kitten
            [37] => had
            [38] => been
            [39] => having
            [40] => a
            [41] => grand
            [42] => game
            [43] => of
            [44] => romps
            [45] => with
            [46] => the
            [47] => ball
            [48] => of
            [49] => worsted
            [50] => Alice
            [51] => had
            [52] => been
            [53] => trying
            [54] => to
            [55] => wind up,
            [57] => and
            [58] => had
            [59] => been
            [60] => rolling
            [61] => it
            [62] => up
            [63] => and
            [64] => down
            [65] => till
            [66] => it
            [67] => had
            [68] => all
            [69] => come
            [70] => undone
            [71] => again;
            [72] => and
            [73] => there
            [74] => it
            [75] => was,
            [76] => spread
            [77] => over
            [78] => the
            [79] => hearth-rug,
            [80] => all
            [81] => knots
            [82] => and
            [83] => tangles,
            [84] => with
            [85] => the
            [86] => kitten
            [87] => running
            [88] => after
            [89] => its
            [90] => own
            [91] => tail
            [93] => the
            [94] => middle.
            [95] => 
        )

    [3] => Array
        (
            [0] => 
            [1] => ‘Oh,
            [2] => you
            [3] => wicked
            [4] => little
            [5] => thing!’
            [6] => cried
            [7] => Alice,
            [8] => catching up
            [10] => the
            [11] => kitten,
            [12] => and
            [13] => giving
            [14] => it
            [15] => a
            [16] => little
            [17] => kiss
            [18] => to
            [19] => make
            [20] => it
            [21] => understand
            [22] => that
            [23] => it
            [24] => was
            [25] => in
            [26] => disgrace.
            [27] => 
        )

)

And para.log gives me this, like i dont have the last element of array, but i do have an index:

[2019-05-18 20:32:38] Paragraph Key:0Array
(
    [0] => One
    [1] => thing
    [2] => was
    [3] => certain,
    [4] => that
    [5] => the
    [6] => white
    [7] => kitten
    [8] => had
    [9] => had
    [10] => nothing
    [11] => to
    [12] => do
    [13] => with
    [14] => it:
    [15] => —
    [16] => it
    [17] => was
    [18] => the
    [19] => black
    [20] => kitten’s
    [21] => fault
    [22] => entirely.
    [23] => For
    [24] => the
    [25] => white
    [26] => kitten
    [27] => had
    [28] => been
    [29] => having
    [30] => its
    [31] => face
    [32] => washed
    [33] => by
    [34] => the
    [35] => old
    [36] => cat
    [37] => for
    [38] => the
    [39] => last
    [40] => quarter
    [41] => of
    [42] => an
    [43] => hour
    [44] => (and
    [45] => bearing
    [46] => it
    [47] => pretty
    [48] => well,
    [49] => considering);
    [50] => so
    [51] => you
    [52] => see
    [53] => that
    [54] => it
    [55] => couldn’t
    [56] => have
    [57] => had
    [58] => any
    [59] => hand in
    [61] => the
    [62] => mischief.
    [63] => 
)

[2019-05-18 20:32:38] Paragraph Key:1Array
(
    [0] => 
    [1] => The
    [2] => way
    [3] => Dinah
    [4] => washed
    [5] => her
    [6] => children’s
    [7] => faces
    [8] => was
    [9] => this:
    [10] => first
    [11] => she
    [12] => held
    [13] => the
    [14] => poor
    [15] => thing
    [16] => down
    [17] => by
    [18] => its
    [19] => ear
    [20] => with
    [21] => one
    [22] => paw,
    [23] => and
    [24] => then
    [25] => with
    [26] => the
    [27] => other
    [28] => paw
    [29] => she
    [30] => rubbed
    [31] => its
    [32] => face
    [33] => all
    [34] => over,
    [35] => the
    [36] => wrong
    [37] => way,
    [38] => beginning
    [39] => at
    [40] => the
    [41] => nose:
    [42] => and
    [43] => just
    [44] => now,
    [45] => as
    [46] => I
    [47] => said,
    [48] => she
    [49] => was
    [50] => hard
    [51] => at
    [52] => work on
    [54] => the
    [55] => white
    [56] => kitten,
    [57] => which
    [58] => was
    [59] => lying
    [60] => quite
    [61] => still
    [62] => and
    [63] => trying
    [64] => to
    [65] => purr
    [66] => —
    [67] => no
    [68] => doubt
    [69] => feeling
    [70] => that
    [71] => it
    [72] => was
    [73] => all
    [74] => meant
    [75] => for
    [76] => its
    [77] => good.
    [78] => 
)

[2019-05-18 20:32:38] Paragraph Key:2Array
(
    [0] => 
    [1] => But
    [2] => the
    [3] => black
    [4] => kitten
    [5] => had
    [6] => been
    [7] => finished
    [8] => with
    [9] => earlier
    [10] => in
    [11] => the
    [12] => afternoon,
    [13] => and
    [14] => so,
    [15] => while
    [16] => Alice
    [17] => was
    [18] => sitting
    [19] => curled
    [20] => up
    [21] => in
    [22] => a
    [23] => corner
    [24] => of
    [25] => the
    [26] => great
    [27] => arm-chair,
    [28] => half
    [29] => talking
    [30] => to
    [31] => herself
    [32] => and
    [33] => half
    [34] => asleep,
    [35] => the
    [36] => kitten
    [37] => had
    [38] => been
    [39] => having
    [40] => a
    [41] => grand
    [42] => game
    [43] => of
    [44] => romps
    [45] => with
    [46] => the
    [47] => ball
    [48] => of
    [49] => worsted
    [50] => Alice
    [51] => had
    [52] => been
    [53] => trying
    [54] => to
    [55] => wind up,
    [57] => and
    [58] => had
    [59] => been
    [60] => rolling
    [61] => it
    [62] => up
    [63] => and
    [64] => down
    [65] => till
    [66] => it
    [67] => had
    [68] => all
    [69] => come
    [70] => undone
    [71] => again;
    [72] => and
    [73] => there
    [74] => it
    [75] => was,
    [76] => spread
    [77] => over
    [78] => the
    [79] => hearth-rug,
    [80] => all
    [81] => knots
    [82] => and
    [83] => tangles,
    [84] => with
    [85] => the
    [86] => kitten
    [87] => running
    [88] => after
    [89] => its
    [90] => own
    [91] => tail
    [93] => the
    [94] => middle.
    [95] => 
)

[2019-05-18 20:32:38] Paragraph Key:3

Any suggestions?

So, i found the solution in the php Bug report: https://bugs.php.net/bug.php?id=60534

Which means that i have to use & (reference) even if i don't need it, just to avoid this bug

PHP version 5.6.33

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM